Example #1
0
        public static void Test()
        {
            var      midiFile = new MidiFile();
            TempoMap tempoMap = midiFile.GetTempoMap();

            var trackChunk = new TrackChunk();

            using (var notesManager = trackChunk.ManageNotes())
            {
                NotesCollection notes = notesManager.Notes;

                var      g = Enum.GetValues(typeof(NoteName));
                NoteName n = (NoteName)g.GetValue(MainWindow._rnd.Next(g.Length));
                notes.Add(new InterNote(n, 4, LC.ConvertFrom(
                                            new MetricTimeSpan(hours: 0, minutes: 0, seconds: 2), 0, tempoMap)));

                n = (NoteName)g.GetValue(MainWindow._rnd.Next(g.Length));
                notes.Add(new InterNote(n, 3, LC.ConvertFrom(
                                            new MetricTimeSpan(hours: 0, minutes: 0, seconds: 1, milliseconds: 500), 0, tempoMap)));
                n = (NoteName)g.GetValue(MainWindow._rnd.Next(g.Length));

                notes.Add(new InterNote(n, 5, LC.ConvertFrom(
                                            new MetricTimeSpan(hours: 0, minutes: 0, seconds: 3), 0, tempoMap)));
            }

            midiFile.Chunks.Add(trackChunk);

            using (var outputDevice = OutputDevice.GetByName("Microsoft GS Wavetable Synth"))
                using (var playback = midiFile.GetPlayback(outputDevice))
                {
                    // playback.Speed = 2.0;
                    playback.Play();
                }
        }
        public async void getNotes(string noteBookId)
        {
            //if (DataBaseHelper.tableExists<Notes>())
            //{
            //    using (SQLiteConnection con = new SQLiteConnection(DataBaseHelper.dbfile))
            //    {
            //        var notes = con.Table<Notes>().
            //                        Where(n => n.NoteBookId.Equals(notebookid)).
            //                        ToList();

            //        NotesCollection.Clear();
            //        foreach (var note in notes)
            //        {
            //            NotesCollection.Add(note);
            //        }
            //    }
            //}
            try
            {
                var notes = await App.MobileServiceClient.GetTable <Notes>().
                            Where(n => n.NoteBookId == noteBookId).ToListAsync();

                NotesCollection.Clear();
                foreach (var note in notes)
                {
                    NotesCollection.Add(note);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exceptionin getting notes" + e.Message);
            }
        }
Example #3
0
 private void LoadNotesCollection()
 {
     if (Notes != null)
     {
         foreach (Note Note in Notes)
         {
             NotesCollection.Add(Note);
         }
     }
 }
Example #4
0
        public void InitPlay()
        {
            _midiFile = new MidiFile();
            TempoMap tempoMap = _midiFile.GetTempoMap();

            var trackChunk = new TrackChunk();

            using (var notesManager = trackChunk.ManageNotes())
            {
                NotesCollection notes = notesManager.Notes;
                var             len   = LC.ConvertFrom(new MetricTimeSpan(hours: 0, minutes: 0, seconds: 1), 0, tempoMap);

                notes.Add(new InterNote(Note, Octave, len));
            }


            _midiFile.Chunks.Add(trackChunk);
        }
Example #5
0
        public static MidiFile ToMidiFile(this Bitmap bitmap, TimeSpan songLength)
        {
            bool newPixelSet    = true;
            var  metricTimeSpan = new MetricTimeSpan(songLength);

            var      midiFile = new MidiFile();
            TempoMap tempoMap = midiFile.GetTempoMap();

            long maxLength = TimeConverter.ConvertFrom(metricTimeSpan, tempoMap);

            List <MidiPixelSet> pixelSet = new List <MidiPixelSet>();

            MidiPixelSet midiPixelSet = new();

            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    var pixel = bitmap.GetPixel(i, j);

                    if (pixel.A == 0)
                    {
                        break;
                    }


                    if (newPixelSet)
                    {
                        midiPixelSet      = new();
                        midiPixelSet.Tone = new(pixel.R, pixel.G, pixel.B);
                    }
                    else
                    {
                        midiPixelSet.Timing = new(pixel.R, pixel.G, pixel.B, maxLength);
                        pixelSet.Add(midiPixelSet);
                    }

                    newPixelSet = !newPixelSet;
                }
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(pixelSet[i].Tone.NoteNumber);
            }



            var trackChunk = new TrackChunk();
            int count      = 0;

            using (var notesManager = trackChunk.ManageNotes())
            {
                NotesCollection notes = notesManager.Notes;
                pixelSet.ForEach(x =>
                {
                    count++;
                    notes.Add(new Note(x.Tone.NoteNumber, x.Tone.Length, x.Timing.Time));
                });
            }

            midiFile.Chunks.Add(trackChunk);
            return(midiFile);
        }
Example #6
0
 public async Task AddNoteAsync()
 {
     NotesCollection.Add(new NoteModel());
     await Task.FromResult(SelectedNote = NotesCollection.LastOrDefault());
 }