/// <summary>Generates a C# code file that when compiled and executed will create the specified MidiSequence.</summary> /// <param name="sequence">The sequence to be codified.</param> /// <param name="namespaceName">The namespace to be used in the generated code.</param> /// <param name="typeName">The type name to be used in the generated code.</param> public void Generate(MidiSequence sequence, string namespaceName, string typeName) { string trackName = sequence.Select(t => t.TrackName).Where(s => s != null).FirstOrDefault(); Ln("using MidiSharp;"); Ln("using MidiSharp.Events;"); Ln("using MidiSharp.Events.Meta;"); Ln("using MidiSharp.Events.Meta.Text;"); Ln("using MidiSharp.Events.Voice;"); Ln("using MidiSharp.Events.Voice.Note;"); Ln("using System.Collections.Generic;"); Ln(); Ln("namespace ", namespaceName); using (Braces()) { Ln("/// <summary>Provides a method for creating the ", (trackName != null ? TextString(trackName) : typeName), " MIDI sequence.</summary>"); Ln("public class ", typeName); using (Braces()) { Ln("/// <summary>Creates the MIDI sequence.</summary>"); Ln("public static MidiSequence CreateSequence()"); using (Braces()) { Ln("MidiSequence sequence = new MidiSequence(MidiSharp.Format.", sequence.Format, ", ", sequence.Division, ");"); for (int i = 0; i < sequence.Tracks.Count; i++) { Ln("sequence.Tracks.Add(CreateTrack", i, "());"); } Ln("return sequence;"); } Ln(); for (int i = 0; i < sequence.Tracks.Count; i++) { if (i != 0) { Ln(); } Ln("/// <summary>Creates track #", i, " in the MIDI sequence.</summary>"); Ln("private static MidiTrack CreateTrack", i, "()"); using (Braces()) { Ln("MidiTrack track = new MidiTrack();"); Ln("MidiEventCollection ", EventsListName, " = track.Events;"); foreach (MidiEvent ev in sequence.Tracks[i].Events) { GenerateAddEvent(ev); } Ln("return track;"); } } } } }