Converts MIDI files into music box scores that are ready to print.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using Melanchall.DryWetMidi.Smf;
|
|
|
|
|
using Melanchall.DryWetMidi.Smf.Interaction;
|
|
|
|
|
|
|
|
|
|
namespace MusicBoxConverter
|
|
|
|
|
{
|
|
|
|
|
public class MusicBoxScoreGenerator
|
|
|
|
|
{
|
|
|
|
|
public float horizontalScaleFactor = 0.1f;
|
|
|
|
|
public float verticalScaleFactor = 4f;
|
|
|
|
|
|
|
|
|
|
MidiFile midiFile;
|
|
|
|
|
|
|
|
|
|
public MusicBoxScoreGenerator(string filename)
|
|
|
|
|
{
|
|
|
|
|
midiFile = MidiFile.Read("/home/sbrl/Music/Sheets/HappyBirthday.midi");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Output(string destinationFilename)
|
|
|
|
|
{
|
|
|
|
|
SvgWriter svg = new SvgWriter(destinationFilename);
|
|
|
|
|
|
|
|
|
|
foreach(TrackChunk chunk in midiFile.Chunks.OfType<TrackChunk>())
|
|
|
|
|
{
|
|
|
|
|
using(NotesManager notesManager = new NotesManager(chunk.Events))
|
|
|
|
|
{
|
|
|
|
|
foreach(Note note in notesManager.Notes)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("[{0}] {1}/{2}", note.Time, note.NoteName, note.NoteNumber);
|
|
|
|
|
svg.WriteCircle(
|
|
|
|
|
(int)(note.Time * horizontalScaleFactor),
|
|
|
|
|
(int)(note.NoteNumber * verticalScaleFactor),
|
|
|
|
|
5
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|