Start working on clipping unsupported notes & removing dead space

This commit is contained in:
Starbeamrainbowlabs 2017-12-02 20:47:40 +00:00
parent 09dd4eed31
commit d527ac2184
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
5 changed files with 46 additions and 5 deletions

View file

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

View file

@ -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" />

View file

@ -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)));

View file

@ -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
);

View file

@ -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);
}
}
}