private static MidiFile ConvertCsvToMidiFile( MidiFileCsvLayout layout, TimeSpanType timeType, string[] csvLines, NoteFormat noteFormat = NoteFormat.Events, NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber, TimeSpanType noteLengthType = TimeSpanType.Midi) { var filePath = Path.GetTempFileName(); FileOperations.WriteAllLinesToFile(filePath, csvLines); var settings = new MidiFileCsvConversionSettings { CsvLayout = layout, TimeType = timeType, NoteFormat = noteFormat, NoteNumberFormat = noteNumberFormat, NoteLengthType = noteLengthType }; try { var midiFile = new CsvConverter().ConvertCsvToMidiFile(filePath, settings); ConvertMidiFileToFromCsv(midiFile, filePath, settings); return(midiFile); } finally { FileOperations.DeleteFile(filePath); } }
private static void ConvertMidiFileToCsv( MidiFile midiFile, MidiFileCsvLayout layout, TimeSpanType timeType, string[] expectedCsvLines, NoteFormat noteFormat = NoteFormat.Events, NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber, TimeSpanType noteLengthType = TimeSpanType.Midi) { var filePath = Path.GetTempFileName(); var settings = new MidiFileCsvConversionSettings { CsvLayout = layout, TimeType = timeType, NoteFormat = noteFormat, NoteNumberFormat = noteNumberFormat, NoteLengthType = noteLengthType }; try { new CsvConverter().ConvertMidiFileToCsv(midiFile, filePath, true, settings); var actualCsvLines = File.ReadAllLines(filePath); CollectionAssert.AreEqual(expectedCsvLines, actualCsvLines, StringComparer.OrdinalIgnoreCase); } finally { File.Delete(filePath); } }
public void ConvertMidiFileToCsv_MultipleTrack(MidiFileCsvLayout layout, NoteFormat noteFormat, NoteNumberFormat noteNumberFormat, string[] expectedCsvLines) { var timedEvents1 = new[] { new TimedEvent(new TimeSignatureEvent(2, 8), 0), new TimedEvent(new TextEvent("Test text"), 345), new TimedEvent(new NoteOnEvent((SevenBitNumber)23, (SevenBitNumber)78), 350), new TimedEvent(new NoteOffEvent((SevenBitNumber)23, (SevenBitNumber)90), 450), new TimedEvent(new SequencerSpecificEvent(new byte[] { 1, 2, 3 }), 800) }; var timedEvents2 = new[] { new TimedEvent(new NoteOnEvent((SevenBitNumber)30, (SevenBitNumber)78), 10), new TimedEvent(new NoteOffEvent((SevenBitNumber)30, (SevenBitNumber)90), 20) }; var midiFile = new MidiFile( timedEvents1.ToTrackChunk(), timedEvents2.ToTrackChunk()); ConvertMidiFileToCsv(midiFile, layout, TimeSpanType.Midi, expectedCsvLines, noteFormat, noteNumberFormat); }