Browse Source

Finish up note validation

main
Starbeamrainbowlabs 4 years ago
parent
commit
09dd4eed31
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 23
      MusicBoxConverter/MusicBox.cs
  2. 37
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  3. 3
      MusicBoxConverter/Program.cs

23
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<string> ValidNotes { get; private set; }
private MusicBox(List<string> inValidNotes)
private MusicBox(string inName, List<string> inValidNotes)
{
Name = inName;
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>
/// A 30 note music box.
/// @Starbeamrainbowlabs has one of these - it was the part of the
/// inspiration for the whole project!
/// </summary>
public static MusicBox Note30 = new MusicBox(
"30 Note Music Box",
new List<string>() {
"G3",
"C4", "D4", "E4", "F4", "G4", "A4", "A#4", "B4",

37
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)

3
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");
}

Loading…
Cancel
Save