public List <byte> createMetaBytes() { List <byte> data = new List <byte>(); if (type.Equals("sequence_number")) { data.Add((byte)(number >> 8)); data.Add((byte)(number & 0xff)); } if (type.Equals("text") || type.Equals("copyright") || type.Equals("lyrics") || type.Equals("marker") || type.Equals("cue_marker")) { if (text == null) { text = ""; } data.AddRange(MidiExport.ascii.GetBytes(text)); } if (type.Equals("track_name") || type.Equals("instrument_name") || type.Equals("device_name")) { data.AddRange(MidiExport.ascii.GetBytes(name)); } if (type.Equals("channel_prefix")) { data.Add((byte)channel); } if (type.Equals("midi_port")) { data.Add((byte)port); } if (type.Equals("set_tempo")) { //return [tempo >> 16, tempo >> 8 & 0xff, tempo & 0xff] data.Add((byte)(tempo >> 16)); data.Add((byte)((tempo >> 8) & 0xff)); data.Add((byte)(tempo & 0xff)); } if (type.Equals("time_signature")) { data.Add((byte)numerator); data.Add((byte)Math.Log(denominator, 2)); data.Add((byte)clocks_per_click); data.Add((byte)notated_32nd_notes_per_beat); } if (type.Equals("key_signature")) { data.Add((byte)(key & 0xff)); data.Add(is_major ? (byte)0x00 : (byte)0x01); } int dataLength = data.Count; data.InsertRange(0, MidiExport.encodeVariableInt(dataLength)); data.Insert(0, code); data.Insert(0, 0xff); return(data); }
public MidiExport GetMidi() { MidiExport result = null; NativeFormat toExport = null; toExport = new NativeFormat() { Title = _song.Title, Subtitle = _song.Subtitle, Album = _song.Album, Annotations = _song.Annotations, Artist = _song.Artist, BarMaster = _song.BarMaster, Directions = _song.Directions, Lyrics = _song.Lyrics, Music = _song.Music, Words = _song.Words }; foreach (DataGridViewRow row in dgvTempos.Rows) { if (row.Cells != null && row.Cells.Count > 0 && row.Cells[0].Value != null && row.Cells[1].Value != null) { toExport.Tempos.Add(new Tempo() { Value = float.Parse(row.Cells[0].Value.ToString()), Position = int.Parse(row.Cells[1].Value.ToString()) }); } } foreach (DataGridViewRow row in dgvTracks.Rows) { if (row.Cells != null && row.Cells.Count > 0 && row.Cells[0].Value != null && row.Cells[1].Value != null) { if ((bool)row.Cells[0].Value == true) { toExport.Tracks.Add(_song.Tracks.Find(p => p.Name == row.Cells[1].Value.ToString())); } } } result = toExport.ToMidi(); return(result); }
public List <byte> createBytes() { List <byte> data = new List <byte>(); byte runningStatusByte = 0x00; bool statusByteSet = false; foreach (MidiMessage message in messages) { if (message.time < 0) { message.time = 0; } data.AddRange(MidiExport.encodeVariableInt(message.time)); if (message.type.Equals("sysex")) { statusByteSet = false; data.Add(0xf0); data.AddRange(MidiExport.encodeVariableInt(message.data.Length + 1)); data.AddRange(message.data); data.Add(0xf7); } else { List <byte> raw = new List <byte>(); raw = message.createBytes(); byte temp = raw[0]; if (statusByteSet && !message.is_meta && raw[0] < 0xf0 && raw[0] == runningStatusByte) { raw.RemoveAt(0); data.AddRange(raw); } else { data.AddRange(raw); } runningStatusByte = temp; statusByteSet = true; } } return(MidiExport.writeChunk("MTrk", data)); }