annotate data/fileio/MIDIFileWriter.h @ 748:c8ab5f63360d

Fixes to copyright notes
author Chris Cannam
date Mon, 03 Sep 2012 11:08:45 +0100
parents 73537d900d4b
children d6bd5751b8f6
rev   line source
Chris@301 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@301 2
Chris@301 3 /*
Chris@301 4 Sonic Visualiser
Chris@301 5 An audio file viewer and annotation editor.
Chris@301 6 Centre for Digital Music, Queen Mary, University of London.
Chris@301 7
Chris@301 8 This program is free software; you can redistribute it and/or
Chris@301 9 modify it under the terms of the GNU General Public License as
Chris@301 10 published by the Free Software Foundation; either version 2 of the
Chris@301 11 License, or (at your option) any later version. See the file
Chris@301 12 COPYING included with this distribution for more information.
Chris@301 13 */
Chris@301 14
Chris@301 15
Chris@301 16 /*
Chris@301 17 This is a modified version of a source file from the
Chris@301 18 Rosegarden MIDI and audio sequencer and notation editor.
Chris@301 19 This file copyright 2000-2007 Richard Bown and Chris Cannam
Chris@301 20 and copyright 2007 QMUL.
Chris@301 21 */
Chris@301 22
Chris@301 23 #ifndef _MIDI_FILE_WRITER_H_
Chris@301 24 #define _MIDI_FILE_WRITER_H_
Chris@301 25
Chris@301 26 #include "base/RealTime.h"
Chris@301 27
Chris@301 28 #include <QString>
Chris@301 29
Chris@301 30 #include <vector>
Chris@301 31 #include <map>
Chris@301 32 #include <fstream>
Chris@301 33
Chris@301 34 class MIDIEvent;
Chris@301 35 class NoteModel;
Chris@301 36
Chris@301 37 /**
Chris@301 38 * Write a MIDI file. This includes file write code for generic
Chris@301 39 * simultaneous-track MIDI files, but the conversion stage only
Chris@301 40 * supports a single-track MIDI file with fixed tempo, time signature
Chris@301 41 * and timing division.
Chris@301 42 */
Chris@301 43 class MIDIFileWriter
Chris@301 44 {
Chris@301 45 public:
Chris@301 46 MIDIFileWriter(QString path, NoteModel *model, float tempo = 120.f);
Chris@301 47 virtual ~MIDIFileWriter();
Chris@301 48
Chris@301 49 virtual bool isOK() const;
Chris@301 50 virtual QString getError() const;
Chris@301 51
Chris@301 52 virtual void write();
Chris@301 53
Chris@301 54 protected:
Chris@301 55 typedef std::vector<MIDIEvent *> MIDITrack;
Chris@301 56 typedef std::map<unsigned int, MIDITrack> MIDIComposition;
Chris@301 57
Chris@301 58 typedef enum {
Chris@301 59 MIDI_SINGLE_TRACK_FILE = 0x00,
Chris@301 60 MIDI_SIMULTANEOUS_TRACK_FILE = 0x01,
Chris@301 61 MIDI_SEQUENTIAL_TRACK_FILE = 0x02,
Chris@301 62 MIDI_FILE_BAD_FORMAT = 0xFF
Chris@301 63 } MIDIFileFormatType;
Chris@301 64
Chris@301 65 std::string intToMIDIBytes(int number) const;
Chris@301 66 std::string longToMIDIBytes(unsigned long number) const;
Chris@301 67 std::string longToVarBuffer(unsigned long number) const;
Chris@301 68
Chris@301 69 unsigned long getMIDITimeForTime(RealTime t) const;
Chris@301 70
Chris@301 71 bool writeHeader();
Chris@301 72 bool writeTrack(int track);
Chris@301 73 bool writeComposition();
Chris@301 74
Chris@301 75 bool convert();
Chris@301 76
Chris@301 77 QString m_path;
Chris@301 78 NoteModel *m_model;
Chris@301 79 bool m_modelUsesHz;
Chris@301 80 float m_tempo;
Chris@301 81 int m_timingDivision; // pulses per quarter note
Chris@301 82 MIDIFileFormatType m_format;
Chris@301 83 unsigned int m_numberOfTracks;
Chris@301 84
Chris@301 85 MIDIComposition m_midiComposition;
Chris@301 86
Chris@301 87 std::ofstream *m_midiFile;
Chris@301 88 QString m_error;
Chris@301 89 };
Chris@301 90
Chris@301 91 #endif