Exemplo n.º 1
0
 public MusicSheet(string title, string instrument, MetronomeMark metronomeMark, IEnumerable <ChordOffset> melody)
 {
     MetronomeMark = metronomeMark;
     Melody        = melody;
     Instrument    = instrument;
     Title         = title;
 }
Exemplo n.º 2
0
        public void Play(InstrumentType instrument, MetronomeMark metronomeMark, ChordOffset[] melody)
        {
            PrepareChordsOctave(instrument, melody[0].Chord);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (var strumIndex = 0; strumIndex < melody.Length;)
            {
                var strum = melody[strumIndex];

                if (stopwatch.ElapsedMilliseconds > metronomeMark.WholeNoteLength.Multiply(strum.Offest).TotalMilliseconds)
                {
                    var chord = strum.Chord;

                    PlayChord(instrument, chord);

                    if (strumIndex < melody.Length - 1)
                    {
                        PrepareChordsOctave(instrument, melody[strumIndex + 1].Chord);
                    }

                    strumIndex++;
                }
                else
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(1));
                }
            }

            stopwatch.Stop();
        }
Exemplo n.º 3
0
        public void Play(Harp harp, MetronomeMark metronomeMark, ChordOffset[] melody)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (var strumIndex = 0; strumIndex < melody.Length;)
            {
                var strum = melody[strumIndex];

                if (stopwatch.ElapsedMilliseconds > metronomeMark.WholeNoteLength.Multiply(strum.Offest).TotalMilliseconds)
                {
                    var chord = strum.Chord;

                    foreach (var note in chord.Notes)
                    {
                        harp.GoToOctave(note);
                        harp.PlayNote(note);
                    }

                    strumIndex++;
                }
                else
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(1));
                }
            }

            stopwatch.Stop();
        }
Exemplo n.º 4
0
        public MusicSheet Parse(string midiPath)
        {
            var midi = new MidiFile(midiPath);

            var metronomeMark = new MetronomeMark(Metronome(midi), BeatsPerMeasure(midi));

            return(new MusicSheet(Path.GetFileNameWithoutExtension(midiPath), metronomeMark, Melody(midi, metronomeMark)));
        }
Exemplo n.º 5
0
        private static Beat Offset(long absoluteTime, MetronomeMark metronomeMark)
        {
            decimal
                time            = absoluteTime,
                wholeNoteLength = (decimal)metronomeMark.WholeNoteLength.TotalMilliseconds;

            var beatsPerMeasure = metronomeMark.BeatsPerMeasure;

            return(new Beat(time / wholeNoteLength / beatsPerMeasure));
        }
Exemplo n.º 6
0
 private static IEnumerable <ChordOffset> Melody(MidiFile midi, MetronomeMark metronomeMark)
 {
     return(midi.Events
            .SelectMany(@event => @event)
            .OfType <NoteOnEvent>()
            .Where(MidiEvent.IsNoteOn)
            .Where(note => note.NoteNumber >= MidiNoteC3 && note.NoteNumber <= MidiNoteC6)
            .GroupBy(@event => @event.AbsoluteTime)
            .OrderBy(group => group.Key)
            .Select(x => ChordOffset(x, metronomeMark)));
 }
Exemplo n.º 7
0
 private static ChordOffset ChordOffset(IGrouping <long, NoteOnEvent> midiEvents, MetronomeMark metronomeMark)
 {
     return(new ChordOffset(Chord(midiEvents), Offset(midiEvents.Key, metronomeMark)));
 }
Exemplo n.º 8
0
        public void it_calculates_length(int metronome, int nominator, int denominator, string expected)
        {
            var metronomeMark = new MetronomeMark(metronome, new Fraction(nominator, denominator));

            Assert.That(metronomeMark.WholeNoteLength, Is.EqualTo(TimeSpan.Parse(expected)));
        }