drumstick
1.0.2
|
00001 /* 00002 MIDI Sequencer C++ library 00003 Copyright (C) 2006-2015, Pedro Lopez-Cabanillas <plcl@users.sf.net> 00004 00005 This library is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef DRUMSTICK_ALSACLIENT_H 00021 #define DRUMSTICK_ALSACLIENT_H 00022 00023 #include "alsaport.h" 00024 #include <QPointer> 00025 #include <QThread> 00026 #include <QReadWriteLock> 00027 00036 namespace drumstick { 00037 00038 class MidiQueue; 00039 class MidiClient; 00040 class SequencerEvent; 00041 class SequencerInputThread; 00042 class RemoveEvents; 00043 00050 class DRUMSTICK_EXPORT ClientInfo 00051 { 00052 friend class MidiClient; 00053 00054 public: 00055 ClientInfo(); 00056 ClientInfo(const ClientInfo& other); 00057 ClientInfo(snd_seq_client_info_t* other); 00058 ClientInfo(MidiClient* seq, int id); 00059 virtual ~ClientInfo(); 00060 ClientInfo* clone(); 00061 ClientInfo& operator=(const ClientInfo& other); 00062 int getSizeOfInfo() const; 00063 00064 int getClientId(); 00065 snd_seq_client_type_t getClientType(); 00066 QString getName(); 00067 bool getBroadcastFilter(); 00068 bool getErrorBounce(); 00069 int getNumPorts(); 00070 int getEventLost(); 00071 void setClient(int client); 00072 void setName(QString name); 00073 void setBroadcastFilter(bool val); 00074 void setErrorBounce(bool val); 00075 PortInfoList getPorts() const; 00076 00077 #if SND_LIB_VERSION > 0x010010 00078 void addFilter(int eventType); 00079 bool isFiltered(int eventType); 00080 void clearFilter(); 00081 void removeFilter(int eventType); 00082 #endif 00083 00084 protected: 00085 void readPorts(MidiClient* seq); 00086 void freePorts(); 00087 00088 const unsigned char* getEventFilter() __attribute__((deprecated)); 00089 void setEventFilter(unsigned char* filter) __attribute__((deprecated)); 00090 00091 private: 00092 snd_seq_client_info_t* m_Info; 00093 PortInfoList m_Ports; 00094 }; 00095 00099 typedef QList<ClientInfo> ClientInfoList; 00100 00107 class DRUMSTICK_EXPORT SystemInfo 00108 { 00109 friend class MidiClient; 00110 00111 public: 00112 SystemInfo(); 00113 SystemInfo(const SystemInfo& other); 00114 SystemInfo(snd_seq_system_info_t* other); 00115 SystemInfo(MidiClient* seq); 00116 virtual ~SystemInfo(); 00117 SystemInfo* clone(); 00118 SystemInfo& operator=(const SystemInfo& other); 00119 int getSizeOfInfo() const; 00120 00121 int getMaxClients(); 00122 int getMaxPorts(); 00123 int getMaxQueues(); 00124 int getMaxChannels(); 00125 int getCurrentQueues(); 00126 int getCurrentClients(); 00127 00128 private: 00129 snd_seq_system_info_t* m_Info; 00130 }; 00131 00138 class DRUMSTICK_EXPORT PoolInfo 00139 { 00140 friend class MidiClient; 00141 00142 public: 00143 PoolInfo(); 00144 PoolInfo(const PoolInfo& other); 00145 PoolInfo(snd_seq_client_pool_t* other); 00146 PoolInfo(MidiClient* seq); 00147 virtual ~PoolInfo(); 00148 PoolInfo* clone(); 00149 PoolInfo& operator=(const PoolInfo& other); 00150 int getSizeOfInfo() const; 00151 00152 int getClientId(); 00153 int getInputFree(); 00154 int getInputPool(); 00155 int getOutputFree(); 00156 int getOutputPool(); 00157 int getOutputRoom(); 00158 void setInputPool(int size); 00159 void setOutputPool(int size); 00160 void setOutputRoom(int size); 00161 00162 private: 00163 snd_seq_client_pool_t* m_Info; 00164 }; 00165 00175 class DRUMSTICK_EXPORT SequencerEventHandler 00176 { 00177 public: 00179 virtual ~SequencerEventHandler() {} 00180 00190 virtual void handleSequencerEvent(SequencerEvent* ev) = 0; 00191 }; 00192 00198 class DRUMSTICK_EXPORT MidiClient : public QObject 00199 { 00200 Q_OBJECT 00201 public: 00202 MidiClient( QObject* parent = 0 ); 00203 virtual ~MidiClient(); 00204 00205 void open( const QString deviceName = "default", 00206 const int openMode = SND_SEQ_OPEN_DUPLEX, 00207 const bool blockMode = false ); 00208 void open( snd_config_t* conf, 00209 const QString deviceName = "default", 00210 const int openMode = SND_SEQ_OPEN_DUPLEX, 00211 const bool blockMode = false ); 00212 void close(); 00213 void startSequencerInput(); 00214 void stopSequencerInput(); 00215 MidiPort* createPort(); 00216 MidiQueue* createQueue(); 00217 MidiQueue* createQueue(QString const& name); 00218 MidiQueue* getQueue(); 00219 MidiQueue* useQueue(int queue_id); 00220 MidiQueue* useQueue(const QString& name); 00221 MidiQueue* useQueue(MidiQueue* queue); 00222 void portAttach(MidiPort* port); 00223 void portDetach(MidiPort* port); 00224 void detachAllPorts(); 00225 void addEventFilter(int evtype); 00226 void output(SequencerEvent* ev, bool async = false, int timeout = -1); 00227 void outputDirect(SequencerEvent* ev, bool async = false, int timeout = -1); 00228 void outputBuffer(SequencerEvent* ev); 00229 void drainOutput(bool async = false, int timeout = -1); 00230 void synchronizeOutput(); 00231 00232 int getClientId(); 00233 snd_seq_type_t getSequencerType(); 00234 snd_seq_t* getHandle(); 00235 bool isOpened(); 00236 00237 size_t getOutputBufferSize(); 00238 void setOutputBufferSize(size_t newSize); 00239 size_t getInputBufferSize(); 00240 void setInputBufferSize(size_t newSize); 00241 QString getDeviceName(); 00242 int getOpenMode(); 00243 bool getBlockMode(); 00244 void setBlockMode(bool newValue); 00245 QString getClientName(); 00246 QString getClientName(const int clientId); 00247 void setClientName(QString const& newName); 00248 bool getBroadcastFilter(); 00249 void setBroadcastFilter(bool newValue); 00250 bool getErrorBounce(); 00251 void setErrorBounce(bool newValue); 00252 00253 ClientInfo& getThisClientInfo(); 00254 void setThisClientInfo(const ClientInfo& val); 00255 MidiPortList getMidiPorts() const; 00256 ClientInfoList getAvailableClients(); 00257 PortInfoList getAvailableInputs(); 00258 PortInfoList getAvailableOutputs(); 00259 SystemInfo& getSystemInfo(); 00260 QList<int> getAvailableQueues(); 00261 00262 PoolInfo& getPoolInfo(); 00263 void setPoolInfo(const PoolInfo& info); 00264 void setPoolInput(int size); 00265 void setPoolOutput(int size); 00266 void setPoolOutputRoom(int size); 00267 void resetPoolInput(); 00268 void resetPoolOutput(); 00269 void dropInput(); 00270 void dropInputBuffer(); 00271 void dropOutput(); 00272 void dropOutputBuffer(); 00273 void removeEvents(const RemoveEvents* spec); 00274 SequencerEvent* extractOutput(); 00275 int outputPending(); 00276 int inputPending(bool fetch); 00277 int getQueueId(const QString& name); 00278 00279 void addListener(QObject* listener); 00280 void removeListener(QObject* listener); 00281 void setEventsEnabled(const bool bEnabled); 00282 bool getEventsEnabled() const; 00283 void setHandler(SequencerEventHandler* handler); 00284 bool parseAddress( const QString& straddr, snd_seq_addr& result ); 00285 void setRealTimeInput(bool enabled); 00286 bool realTimeInputEnabled(); 00287 00288 signals: 00290 void eventReceived(SequencerEvent* ev); 00291 00292 protected: 00293 void doEvents(); 00294 void applyClientInfo(); 00295 void readClients(); 00296 void freeClients(); 00297 void updateAvailablePorts(); 00298 PortInfoList filterPorts(unsigned int filter); 00299 00300 /* low level public functions */ 00301 const char * _getDeviceName(); 00302 int getPollDescriptorsCount(short events); 00303 int pollDescriptors(struct pollfd *pfds, unsigned int space, short events); 00304 unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds); 00305 00306 /* mid level functions */ 00307 void _setClientName( const char *name ); 00308 int createSimplePort( const char *name, 00309 unsigned int caps, 00310 unsigned int type ); 00311 void deleteSimplePort( int port ); 00312 void connectFrom(int myport, int client, int port); 00313 void connectTo(int myport, int client, int port); 00314 void disconnectFrom(int myport, int client, int port); 00315 void disconnectTo(int myport, int client, int port); 00316 00317 private: 00318 class SequencerInputThread; 00319 class MidiClientPrivate; 00320 MidiClientPrivate *d; 00321 }; 00322 00323 #if SND_LIB_VERSION > 0x010004 00324 DRUMSTICK_EXPORT QString getRuntimeALSALibraryVersion(); 00325 DRUMSTICK_EXPORT int getRuntimeALSALibraryNumber(); 00326 #endif 00327 DRUMSTICK_EXPORT QString getRuntimeALSADriverVersion(); 00328 DRUMSTICK_EXPORT int getRuntimeALSADriverNumber(); 00329 00330 } /* namespace drumstick */ 00331 00334 #endif // DRUMSTICK_ALSACLIENT_H