public static void ConvertToCsv(MidiFile midiFile, Stream stream, MidiFileCsvConversionSettings settings)
        {
            using (var streamWriter = new StreamWriter(stream))
            {
                var trackNumber = 0;
                var tempoMap    = midiFile.GetTempoMap();

                WriteHeader(streamWriter, midiFile, settings, tempoMap);

                foreach (var trackChunk in midiFile.GetTrackChunks())
                {
                    WriteTrackChunkStart(streamWriter, trackNumber, settings, tempoMap);

                    var time = 0L;

                    foreach (var timedEvent in trackChunk.GetTimedEvents())
                    {
                        time = timedEvent.Time;
                        var midiEvent = timedEvent.Event;
                        var eventType = midiEvent.GetType();

                        var eventNameGetter = EventNameGetterProvider.Get(eventType, settings.CsvLayout);
                        var recordType      = eventNameGetter(midiEvent);

                        var eventParametersGetter = EventParametersGetterProvider.Get(eventType);
                        var recordParameters      = eventParametersGetter(midiEvent, settings);

                        WriteRecord(streamWriter,
                                    trackNumber,
                                    time,
                                    recordType,
                                    settings,
                                    tempoMap,
                                    recordParameters);
                    }

                    WriteTrackChunkEnd(streamWriter, trackNumber, time, settings, tempoMap);

                    trackNumber++;
                }

                WriteFileEnd(streamWriter, settings, tempoMap);
            }
        }
Exemplo n.º 2
0
        private static void WriteTimedEvent(TimedEvent timedEvent,
                                            CsvWriter csvWriter,
                                            int trackNumber,
                                            long time,
                                            MidiFileCsvConversionSettings settings,
                                            TempoMap tempoMap)
        {
            var midiEvent = timedEvent.Event;
            var eventType = midiEvent.GetType();

            var eventNameGetter = EventNameGetterProvider.Get(eventType, settings.CsvLayout);
            var recordType      = eventNameGetter(midiEvent);

            var eventParametersGetter = EventParametersGetterProvider.Get(eventType);
            var recordParameters      = eventParametersGetter(midiEvent, settings);

            WriteRecord(csvWriter,
                        trackNumber,
                        time,
                        recordType,
                        settings,
                        tempoMap,
                        recordParameters);
        }