2017-11-30 22:45:39 +00:00
|
|
|
|
using System;
|
2017-11-30 23:03:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-11-30 22:45:39 +00:00
|
|
|
|
using System.Linq;
|
2017-11-30 23:03:55 +00:00
|
|
|
|
|
2017-11-30 22:45:39 +00:00
|
|
|
|
using Melanchall.DryWetMidi.Smf;
|
|
|
|
|
using Melanchall.DryWetMidi.Smf.Interaction;
|
|
|
|
|
|
2017-11-30 23:03:55 +00:00
|
|
|
|
using SBRL.Utilities;
|
|
|
|
|
|
2017-11-30 22:45:39 +00:00
|
|
|
|
namespace MusicBoxConverter
|
|
|
|
|
{
|
|
|
|
|
public class MusicBoxScoreGenerator
|
|
|
|
|
{
|
2017-11-30 23:03:55 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2017-11-30 22:45:39 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2017-11-30 23:03:55 +00:00
|
|
|
|
|
|
|
|
|
foreach(Note note in AllNotes())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("[{0}] {1}/{2}", note.Time, note.NoteName, note.NoteNumber);
|
|
|
|
|
svg.WriteCircle(
|
|
|
|
|
new Vector2(
|
|
|
|
|
offset.X + note.Time * scaleFactor.X,
|
|
|
|
|
offset.Y + note.NoteNumber * scaleFactor.Y
|
|
|
|
|
),
|
|
|
|
|
holeSize // radius
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Note> AllNotes()
|
|
|
|
|
{
|
2017-11-30 22:45:39 +00:00
|
|
|
|
foreach(TrackChunk chunk in midiFile.Chunks.OfType<TrackChunk>())
|
|
|
|
|
{
|
|
|
|
|
using(NotesManager notesManager = new NotesManager(chunk.Events))
|
|
|
|
|
{
|
|
|
|
|
foreach(Note note in notesManager.Notes)
|
2017-11-30 23:03:55 +00:00
|
|
|
|
yield return note;
|
2017-11-30 22:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 23:03:55 +00:00
|
|
|
|
public int TrackLength()
|
|
|
|
|
{
|
|
|
|
|
//notesManager.Notes.OfType<TrackChunk>().Select((TrackChunk arg) => arg.Events.O;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2017-11-30 22:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|