Finish up note validation
This commit is contained in:
parent
f71e215b61
commit
09dd4eed31
3 changed files with 45 additions and 18 deletions
|
@ -1,20 +1,36 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Melanchall.DryWetMidi.Smf.Interaction;
|
||||||
|
|
||||||
namespace MusicBoxConverter
|
namespace MusicBoxConverter
|
||||||
{
|
{
|
||||||
public class MusicBox
|
public class MusicBox
|
||||||
{
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
public List<string> ValidNotes { get; private set; }
|
public List<string> ValidNotes { get; private set; }
|
||||||
|
|
||||||
private MusicBox(List<string> inValidNotes)
|
private MusicBox(string inName, List<string> inValidNotes)
|
||||||
{
|
{
|
||||||
|
Name = inName;
|
||||||
ValidNotes = inValidNotes;
|
ValidNotes = inValidNotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsValidNote(string noteName)
|
/// <summary>
|
||||||
|
/// Calculates whether the specified note can be played by this music box.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="note">The note to check.</param>
|
||||||
|
/// <returns>Whether the note can be played by this music box.</returns>
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,6 +39,7 @@ namespace MusicBoxConverter
|
||||||
/// inspiration for the whole project!
|
/// inspiration for the whole project!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static MusicBox Note30 = new MusicBox(
|
public static MusicBox Note30 = new MusicBox(
|
||||||
|
"30 Note Music Box",
|
||||||
new List<string>() {
|
new List<string>() {
|
||||||
"G3",
|
"G3",
|
||||||
"C4", "D4", "E4", "F4", "G4", "A4", "A#4", "B4",
|
"C4", "D4", "E4", "F4", "G4", "A4", "A#4", "B4",
|
||||||
|
|
|
@ -17,19 +17,28 @@ namespace MusicBoxConverter
|
||||||
public int holeSize { get; set; } = 5;
|
public int holeSize { get; set; } = 5;
|
||||||
|
|
||||||
private int trackLength;
|
private int trackLength;
|
||||||
public int TrackLength {
|
public int TrackLength
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
if (trackLength == 0)
|
if (trackLength == 0)
|
||||||
trackLength = (int)AllNotes().Max((Note arg) => arg.Time);
|
trackLength = (int)AllNotes().Max((Note arg) => arg.Time);
|
||||||
return trackLength;
|
return trackLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MusicBox MusicBox { get; private set; }
|
||||||
MidiFile midiFile;
|
MidiFile midiFile;
|
||||||
|
|
||||||
public MusicBoxScoreGenerator(string filename)
|
public MusicBoxScoreGenerator(string filename, MusicBox inMusicBox)
|
||||||
{
|
{
|
||||||
|
MusicBox = inMusicBox;
|
||||||
midiFile = MidiFile.Read("/home/sbrl/Music/Sheets/HappyBirthday.midi");
|
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)
|
public void Output(string destinationFilename)
|
||||||
|
|
|
@ -7,7 +7,8 @@ namespace MusicBoxConverter
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
|
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
|
||||||
"/home/sbrl/Music/Sheets/HappyBirthday.midi"
|
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
|
||||||
|
MusicBox.Note30
|
||||||
);
|
);
|
||||||
converter.Output("/tmp/test.svg");
|
converter.Output("/tmp/test.svg");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue