diff --git a/MusicBoxConverter/MusicBox.cs b/MusicBoxConverter/MusicBox.cs index 3d2cf8a..323d8f3 100644 --- a/MusicBoxConverter/MusicBox.cs +++ b/MusicBoxConverter/MusicBox.cs @@ -1,28 +1,45 @@ using System; using System.Collections.Generic; +using Melanchall.DryWetMidi.Smf.Interaction; namespace MusicBoxConverter { public class MusicBox { + public string Name { get; private set; } public List ValidNotes { get; private set; } - private MusicBox(List inValidNotes) + private MusicBox(string inName, List inValidNotes) { + Name = inName; ValidNotes = inValidNotes; } - public bool IsValidNote(string noteName) + /// + /// Calculates whether the specified note can be played by this music box. + /// + /// The note to check. + /// Whether the note can be played by this music box. + public bool IsValidNote(Note note) { - throw new NotImplementedException(); + return ValidNotes.Contains( + (note.NoteName.ToString() + note.Octave).Replace("Sharp", "") + ); } + public override string ToString() + { + return Name; + //return string.Format("[MusicBox: Name={0}, ValidNotes={1}]", Name, ValidNotes); + } + /// /// A 30 note music box. /// @Starbeamrainbowlabs has one of these - it was the part of the /// inspiration for the whole project! /// public static MusicBox Note30 = new MusicBox( + "30 Note Music Box", new List() { "G3", "C4", "D4", "E4", "F4", "G4", "A4", "A#4", "B4", diff --git a/MusicBoxConverter/MusicBoxScoreGenerator.cs b/MusicBoxConverter/MusicBoxScoreGenerator.cs index d9619c2..64d5db9 100644 --- a/MusicBoxConverter/MusicBoxScoreGenerator.cs +++ b/MusicBoxConverter/MusicBoxScoreGenerator.cs @@ -9,27 +9,36 @@ using SBRL.Utilities; namespace MusicBoxConverter { - public class MusicBoxScoreGenerator - { - public Vector2 offset { get; set; } = new Vector2(10, 10); - public Vector2 scaleFactor { get; set; } = new Vector2(0.1f, 4f); + public class MusicBoxScoreGenerator + { + public Vector2 offset { get; set; } = new Vector2(10, 10); + public Vector2 scaleFactor { get; set; } = new Vector2(0.1f, 4f); - public int holeSize { get; set; } = 5; + public int holeSize { get; set; } = 5; - private int trackLength; - public int TrackLength { - get { - if(trackLength == 0) - trackLength = (int)AllNotes().Max((Note arg) => arg.Time); - return trackLength; - } - } + private int trackLength; + public int TrackLength + { + get + { + if (trackLength == 0) + trackLength = (int)AllNotes().Max((Note arg) => arg.Time); + return trackLength; + } + } + public MusicBox MusicBox { get; private set; } MidiFile midiFile; - public MusicBoxScoreGenerator(string filename) + public MusicBoxScoreGenerator(string filename, MusicBox inMusicBox) { + MusicBox = inMusicBox; midiFile = MidiFile.Read("/home/sbrl/Music/Sheets/HappyBirthday.midi"); + + foreach(Note note in AllNotes()) { + if (!MusicBox.IsValidNote(note)) + throw new Exception($"Error: The note {note} at {note.Time} can't be played by the {MusicBox}."); + } } public void Output(string destinationFilename) diff --git a/MusicBoxConverter/Program.cs b/MusicBoxConverter/Program.cs index 85fdecf..8a8e04f 100644 --- a/MusicBoxConverter/Program.cs +++ b/MusicBoxConverter/Program.cs @@ -7,7 +7,8 @@ namespace MusicBoxConverter public static void Main(string[] args) { MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator( - "/home/sbrl/Music/Sheets/HappyBirthday.midi" + "/home/sbrl/Music/Sheets/HappyBirthday.midi", + MusicBox.Note30 ); converter.Output("/tmp/test.svg"); }