1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 /* 3 Rosegarden 4 A sequencer and musical notation editor. 5 Copyright 2000-2021 the Rosegarden development team. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the 10 License, or (at your option) any later version. See the file 11 COPYING included with this distribution for more information. 12 */ 13 14 15 #ifndef RG_MIDIEVENT_H 16 #define RG_MIDIEVENT_H 17 18 #include "Midi.h" 19 #include "base/Event.h" 20 21 namespace Rosegarden 22 { 23 24 25 /// For standard MIDI file I/O. 26 /** 27 * MidiEvent is a representation of MIDI which we use 28 * for the import/export of MIDI files. It uses std::string for 29 * meta event messages which makes them nice and easy to handle. 30 * 31 * We don't use this class at all for playback or recording of MIDI - 32 * for that look at MappedEvent and MappedEventList. 33 * 34 * Rosegarden doesn't have any internal concept of MIDI events, only 35 * the Event class which offers a superset of MIDI functionality. 36 */ 37 class MidiEvent 38 { 39 40 public: 41 MidiEvent(); 42 43 /// An event with one data byte. E.g. Program Change. 44 MidiEvent(timeT time, 45 MidiByte eventCode, 46 MidiByte data1); 47 48 /// An event with two data bytes. E.g. Note-On. 49 MidiEvent(timeT time, 50 MidiByte eventCode, 51 MidiByte data1, 52 MidiByte data2); 53 54 /// Meta event 55 MidiEvent(timeT time, 56 MidiByte eventCode, 57 MidiByte metaEventCode, 58 const std::string &metaMessage); 59 60 /// Sysex event 61 MidiEvent(timeT time, 62 MidiByte eventCode, 63 const std::string &sysEx); 64 setTime(const timeT & time)65 void setTime(const timeT &time) { m_time = time; } getTime()66 timeT getTime() const { return m_time; } 67 setDuration(const timeT & duration)68 void setDuration(const timeT& duration) { m_duration = duration; } getDuration()69 timeT getDuration() const { return m_duration; } 70 getEventCode()71 MidiByte getEventCode() const { return m_eventCode; } getMessageType()72 MidiByte getMessageType() const 73 { return m_eventCode & MIDI_MESSAGE_TYPE_MASK; } getChannelNumber()74 MidiByte getChannelNumber() const 75 { return m_eventCode & MIDI_CHANNEL_NUM_MASK; } 76 getData1()77 MidiByte getData1() const { return m_data1; } getPitch()78 MidiByte getPitch() const { return m_data1; } 79 getData2()80 MidiByte getData2() const { return m_data2; } getVelocity()81 MidiByte getVelocity() const { return m_data2; } 82 isMeta()83 bool isMeta() const { return (m_eventCode == MIDI_FILE_META_EVENT); } getMetaEventCode()84 MidiByte getMetaEventCode() const { return m_metaEventCode; } setMetaMessage(const std::string & meta)85 void setMetaMessage(const std::string &meta) { m_metaMessage = meta; } getMetaMessage()86 std::string getMetaMessage() const { return m_metaMessage; } 87 88 friend QDebug &operator<<(QDebug &, const MidiEvent &); 89 90 private: 91 /// Delta or absolute time, depending. 92 timeT m_time; 93 timeT m_duration; 94 MidiByte m_eventCode; 95 MidiByte m_data1; 96 MidiByte m_data2; 97 98 MidiByte m_metaEventCode; 99 std::string m_metaMessage; 100 }; 101 102 QDebug &operator<<(QDebug &, const MidiEvent &); 103 104 105 } 106 107 #endif // RG_MIDIEVENT_H 108