46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
|
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();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|