![]() |
Mixxx
|
00001 /*************************************************************************** 00002 mididevice.h 00003 MIDI Device Class 00004 ------------------- 00005 begin : Thu Dec 18 2008 00006 copyright : (C) 2008 Albert Santoni 00007 email : alberts@mixxx.org 00008 00009 This class represents a physical or virtual MIDI device. A MIDI device 00010 processes MIDI messages that are received from it in the receive() 00011 function and MIDI messages can be sent back to it using the send*() 00012 functions. This is a base class that cannot be instantiated on its own, 00013 it must be inherited by a class that implements it on top of some API. 00014 (See MidiDevicePortMidi, as of Nov 2009.) 00015 00016 This class is thread safe and must remain thread safe because parts of 00017 it may be accessed by the MIDI script engine thread as well as the 00018 MIDI thread concurrently. 00019 00020 ***************************************************************************/ 00021 00022 /*************************************************************************** 00023 * * 00024 * This program is free software; you can redistribute it and/or modify * 00025 * it under the terms of the GNU General Public License as published by * 00026 * the Free Software Foundation; either version 2 of the License, or * 00027 * (at your option) any later version. * 00028 * * 00029 ***************************************************************************/ 00030 00031 #ifndef MIDIDEVICE_H 00032 #define MIDIDEVICE_H 00033 00034 #include <QtCore> 00035 #include "midimessage.h" 00036 #include "softtakeover.h" 00037 00038 //Forward declarations 00039 class MidiMapping; 00040 #ifdef __MIDISCRIPT__ 00041 class MidiScriptEngine; 00042 #endif 00043 00044 class MidiDevice : public QThread 00045 { 00046 Q_OBJECT 00047 public: 00048 MidiDevice(MidiMapping* mapping); 00049 virtual ~MidiDevice(); 00050 virtual int open() = 0; 00051 virtual int close() = 0; 00052 virtual void run() = 0; 00053 void startup(); 00054 void shutdown(); 00055 bool isOpen() { return m_bIsOpen; }; 00056 bool isOutputDevice() { return m_bIsOutputDevice; }; 00057 bool isInputDevice() { return m_bIsInputDevice; }; 00058 QString getName() { return m_strDeviceName; }; 00059 void setMidiMapping(MidiMapping* mapping); 00060 MidiMapping* getMidiMapping() { return m_pMidiMapping; }; 00061 Q_INVOKABLE void sendShortMsg(unsigned char status, unsigned char byte1, unsigned char byte2); 00062 virtual void sendShortMsg(unsigned int word); 00063 virtual void sendSysexMsg(unsigned char data[], unsigned int length); 00064 Q_INVOKABLE void sendSysexMsg(QList<int> data, unsigned int length); 00065 bool getMidiLearnStatus(); 00066 void receive(MidiStatusByte status, char channel, char control, char value); 00067 #ifdef __MIDISCRIPT__ 00068 00070 void receive(const unsigned char data[], unsigned int length); 00071 #endif 00072 00074 bool midiDebugging(); 00075 void setReceiveInhibit(bool inhibit); 00076 public slots: 00077 void disableMidiLearn(); 00078 void enableMidiLearn(); 00079 00080 signals: 00081 void midiEvent(MidiMessage message); 00082 void callMidiScriptFunction(QString function, char channel, char control, char value, MidiStatusByte status, QString group); 00083 00084 protected: 00086 QString m_strDeviceName; 00088 bool m_bIsOutputDevice; 00090 bool m_bIsInputDevice; 00092 MidiMapping* m_pMidiMapping; 00094 bool m_bIsOpen; 00096 bool m_bMidiLearn; 00100 MidiDevice* m_pCorrespondingOutputDevice; 00103 bool m_midiDebug; 00105 QMutex m_mutex; 00107 QMutex m_mappingPtrMutex; 00111 bool m_bReceiveInhibit; 00112 SoftTakeover m_st; 00113 }; 00114 00115 #endif