Exemplo n.º 1
0
        public void PlaybackPercentSet(int process)
        {
            if (playback.IsRunning)
            {
                MidiTimeSpan dur = (MidiTimeSpan)playback.GetDuration(TimeSpanType.Midi);

                var tar = new MidiTimeSpan(dur.TimeSpan * process / 100);
                playback.MoveToTime(tar);
            }
        }
Exemplo n.º 2
0
        public static Bitmap ToBitmap(this MidiFile midiFile)
        {
            List <Melanchall.DryWetMidi.Interaction.Note> noteList = new();

            foreach (var trackChunk in midiFile.GetTrackChunks())
            {
                using (var notesManager = trackChunk.ManageNotes())
                {
                    foreach (var note in notesManager.Notes)
                    {
                        noteList.Add(note);
                    }
                }
            }

            var tempoMap = midiFile.GetTempoMap();

            Console.WriteLine(noteList.Average(x => x.Length));
            Console.WriteLine(noteList.Average(x => x.Time));
            Console.WriteLine(noteList.Max(x => x.Time));
            MetricTimeSpan timespan = TimeConverter.ConvertTo <MetricTimeSpan>(noteList.Max(x => x.Time), tempoMap);

            Console.WriteLine(timespan.TotalMicroseconds);
            long things = TimeConverter.ConvertFrom(timespan, tempoMap);

            Console.WriteLine(things);
            MidiTimeSpan duration = midiFile.GetDuration <MidiTimeSpan>();

            Console.WriteLine($"Duration: {duration.TimeSpan}");

            noteList = noteList.OrderBy(x => x.Time).ToList();
            List <MidiPixelSet> notePixels = noteList.Select(n => new MidiPixelSet(n, noteList.Average(x => x.Length), duration.TimeSpan)).ToList();

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

            var dimensions = (int)Math.Ceiling(Math.Sqrt(notePixels.Count * 2));

            if (dimensions % 2 != 0)
            {
                dimensions += 1;
            }

            var bitmap = new Bitmap(dimensions, dimensions);

            int column = 0;
            int row    = 0;
            int count  = 0;

            notePixels.ForEach(x =>
            {
                count++;
                if (column >= (dimensions - 1))
                {
                    column = 0;
                    row++;
                }

                bitmap.SetPixel(row, column, x.Tone.Color);
                column++;
                bitmap.SetPixel(row, column, x.Timing.Color);
                column++;
            });

            return(bitmap);
        }