public MusicSheet(string title, string instrument, MetronomeMark metronomeMark, IEnumerable <ChordOffset> melody) { MetronomeMark = metronomeMark; Melody = melody; Instrument = instrument; Title = title; }
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(); }
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(); }
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))); }
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)); }
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))); }
private static ChordOffset ChordOffset(IGrouping <long, NoteOnEvent> midiEvents, MetronomeMark metronomeMark) { return(new ChordOffset(Chord(midiEvents), Offset(midiEvents.Key, metronomeMark))); }
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))); }