Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/midi/midimessage.h

Go to the documentation of this file.
00001 #ifndef _MIDIMESSAGE_H_
00002 #define _MIDIMESSAGE_H_
00003 
00004 #include <QDebug>
00005 #include "configobject.h"
00006 
00012 typedef enum {
00013     MIDI_STATUS_NOTE_OFF   = 0x80,
00014     MIDI_STATUS_NOTE_ON    = 0x90,
00015     MIDI_STATUS_AFTERTOUCH = 0xA0,
00016     MIDI_STATUS_CC         = 0xB0,
00017     MIDI_STATUS_PROGRAM_CH = 0xC0,
00018     MIDI_STATUS_CH_AFTERTOUCH = 0xD0,
00019     MIDI_STATUS_PITCH_BEND = 0xE0,
00020     MIDI_STATUS_SYSEX      = 0xF0,
00021     MIDI_STATUS_TIME_CODE   = 0xF1,
00022     MIDI_STATUS_SONG_POS    = 0xF2,
00023     MIDI_STATUS_SONG        = 0xF3,
00024     MIDI_STATUS_UNDEFINED1  = 0xF4,
00025     MIDI_STATUS_UNDEFINED2  = 0xF5,
00026     MIDI_STATUS_TUNE_REQ    = 0xF6,
00027     MIDI_STATUS_EOX         = 0xF7,
00028     MIDI_STATUS_TIMING_CLK  = 0xF8,
00029     MIDI_STATUS_UNDEFINED3  = 0xF9,
00030     MIDI_STATUS_START       = 0xFA,
00031     MIDI_STATUS_CONTINUE    = 0xFB,
00032     MIDI_STATUS_STOP        = 0xFC,
00033     MIDI_STATUS_UNDEFINED4  = 0xFD,
00034     MIDI_STATUS_ACTIVE_SENSE= 0xFE,
00035     MIDI_STATUS_SYSTEM_RESET= 0xFF,
00036 } MidiStatusByte;
00037   
00038  // This enum is used in the decoding of the status message into voice categories
00039 // This is just cruft leftover from ages ago, unfortunately. Hasn't been properly removed/refactored yet.
00040 typedef enum {
00041     NOTE_OFF         = 0x80,
00042     NOTE_ON          = 0x90,
00043     AFTERTOUCH       = 0xA0,
00044     CTRL_CHANGE      = 0xB0,
00045     PROG_CHANGE      = 0xC0,
00046     CHANNEL_PRESSURE = 0xD0,
00047     PITCH_WHEEL      = 0xE0,
00048 } MidiCategory; 
00049   
00051   class MidiMessage
00052   {
00053       public:
00054           MidiMessage(MidiStatusByte status=MIDI_STATUS_NOTE_ON, int midino=0, char midichannel=0);
00055           MidiMessage(QDomElement& parentNode);
00056           ~MidiMessage() {};
00057           void setMidiStatusByte(MidiStatusByte status) { m_midiStatusByte = status; };
00058           void setMidiNo(unsigned short midino) { m_midiNo = midino; };
00059           void setMidiChannel(unsigned short midichannel) { m_midiStatusByte |= midichannel; };
00060           unsigned short getMidiStatusByte() const { return m_midiStatusByte; } ;
00061           unsigned short getMidiNo() const { return m_midiNo; };
00062           unsigned short getMidiChannel() const { return m_midiStatusByte & 0x0F; };
00063           unsigned short getMidiByte2On() const { return m_midiByte2On; };
00064           unsigned short getMidiByte2Off() const { return m_midiByte2Off; };
00065           void serializeToXML(QDomElement& parentNode, bool isOutputNode=false) const;
00066           QString toString() const;
00067           bool operator==(const MidiMessage& other) const {
00068             //Compare high bits, which ignores the channel
00069             unsigned short status = this->getMidiStatusByte();
00070             if ((status & 0xF0) == MIDI_STATUS_PITCH_BEND ||
00071                 (status & 0xF0) == MIDI_STATUS_CH_AFTERTOUCH ||
00072                 (status & 0xF0) == MIDI_STATUS_SYSEX) {
00073                 //Ignore midiNo for pitch, channel after-touch and 0xFn messages
00074                 //  because that byte is part of the message payload. (See the MIDI spec.)
00075                 return (this->getMidiStatusByte() == other.getMidiStatusByte());
00076             }
00077             else {
00078                 return ((m_midiStatusByte == other.getMidiStatusByte()) &&
00079                     (m_midiNo == other.getMidiNo()));
00080             }
00081           };
00082   
00083       private:
00084          unsigned short m_midiStatusByte; 
00085          unsigned short m_midiNo;         
00090         unsigned short m_midiByte2On;  
00091         unsigned short m_midiByte2Off; 
00093   };
00094   
00096 uint qHash(const MidiMessage& key);
00097 
00098 inline QDataStream& operator<<(QDataStream & stream, const MidiMessage &first)
00099 {
00100      return stream << first.toString();
00101 }
00102 
00103 /* Linker error wtf?
00104 QDebug operator<<(QDebug dbg, MidiMessage& command)
00105 {
00106     dbg.space() << command.getMidiStatusByte();
00107     dbg.space() << command.getMidiNo();
00108     dbg.space() << command.getMidiChannel();
00109 
00110     return dbg.space();
00111 }*/
00112 
00113 #endif
00114 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines