Browse Source

Start working on clipping unsupported notes & removing dead space

main
Starbeamrainbowlabs 4 years ago
parent
commit
d527ac2184
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 1
      MusicBoxConverter/MusicBox.cs
  2. 1
      MusicBoxConverter/MusicBoxConverter.csproj
  3. 21
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  4. 4
      MusicBoxConverter/Program.cs
  5. 24
      MusicBoxConverter/Utilities/NoteUtilities.cs

1
MusicBoxConverter/MusicBox.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Melanchall.DryWetMidi.Smf.Interaction;
namespace MusicBoxConverter

1
MusicBoxConverter/MusicBoxConverter.csproj

@ -42,6 +42,7 @@
<Compile Include="SvgWriter.cs" />
<Compile Include="Utilities\Vector2.cs" />
<Compile Include="MusicBox.cs" />
<Compile Include="Utilities\NoteUtilities.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

21
MusicBoxConverter/MusicBoxScoreGenerator.cs

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Melanchall.DryWetMidi.Smf;
using Melanchall.DryWetMidi.Smf.Interaction;
@ -27,6 +26,20 @@ namespace MusicBoxConverter
}
}
public int MaxNoteNumber {
get {
// TODO: Update to get the max note number supported by the music box
return AllNotes().Max((Note note) => note.NoteNumber);
}
}
public int MinNoteNumber {
get
{
// TODO: Update to get the min note number supported by the music box
return AllNotes().Min((Note note) => note.NoteNumber);
}
}
public MusicBox MusicBox { get; private set; }
MidiFile midiFile;
@ -37,17 +50,17 @@ namespace MusicBoxConverter
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}.");
Console.Error.WriteLine($"Warning: The note {note} at {note.Time} can't be played by the {MusicBox}.");
}
}
public void Output(string destinationFilename)
{
Vector2 area = new Vector2(TrackLength, 128).Multiply(scaleFactor);
Vector2 area = new Vector2(TrackLength, MaxNoteNumber - MinNoteNumber).Multiply(scaleFactor);
Vector2 size = area.Add(offset.Multiply(2));
SvgWriter svg = new SvgWriter(destinationFilename, size.X.ToString(), size.Y.ToString());
for(int i = 0; i < 127; i += 5)
for(int i = 0; i < area.Y; i += 5)
{
Vector2 start = offset.Add(new Vector2(0, i * scaleFactor.Y));
svg.WriteLine(start, start.Add(new Vector2(TrackLength * scaleFactor.X, 0)));

4
MusicBoxConverter/Program.cs

@ -1,4 +1,6 @@
using System;
using System.Reflection;
using Melanchall.DryWetMidi.Common;
namespace MusicBoxConverter
{
@ -6,7 +8,7 @@ namespace MusicBoxConverter
{
public static void Main(string[] args)
{
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
MusicBox.Note30
);

24
MusicBoxConverter/Utilities/NoteUtilities.cs

@ -0,0 +1,24 @@
using System;
using System.Text.RegularExpressions;
using Melanchall.DryWetMidi.Smf.Interaction;
using Melanchall.DryWetMidi.Common;
using System.Reflection;
namespace MusicBoxConverter
{
static class NoteUtilities
{
public static string NoteToString(Note note)
{
return $"{note.NoteName}{note.Octave}";
}
public static Note StringToNote(string note)
{
string noteLetter = Regex.Replace(note, "[0-9]", "").Replace("#", "Sharp");
int octave = int.Parse(Regex.Replace(note, "[^0-9]", ""));
NoteName noteName = (NoteName)Enum.Parse(typeof(NoteName), noteLetter);
return new Note(noteName, 4);
}
}
}
Loading…
Cancel
Save