1 /* 2 MIDI Sequencer C++ library 3 Copyright (C) 2006-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net> 4 5 This library is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef DRUMSTICK_ALSAQUEUE_H 20 #define DRUMSTICK_ALSAQUEUE_H 21 22 #include <QObject> 23 24 extern "C" { 25 #include <alsa/asoundlib.h> 26 } 27 28 #include "macros.h" 29 30 namespace drumstick { namespace ALSA { 31 32 /** 33 * @file alsaqueue.h 34 * Classes managing ALSA Sequencer queues 35 */ 36 37 class MidiClient; 38 class TimerId; 39 40 /** 41 * @addtogroup ALSAQueue ALSA Sequencer Queues 42 * @{ 43 * 44 * @class QueueInfo 45 * Queue information container. 46 * 47 * This class is used to hold some properties about an ALSA queue object. 48 */ 49 class DRUMSTICK_EXPORT QueueInfo 50 { 51 friend class MidiQueue; 52 53 public: 54 QueueInfo(); 55 QueueInfo(const QueueInfo& other); 56 explicit QueueInfo(snd_seq_queue_info_t* other); 57 virtual ~QueueInfo(); 58 QueueInfo* clone(); 59 QueueInfo& operator=(const QueueInfo& other); 60 int getInfoSize() const; 61 62 int getId(); 63 QString getName(); 64 int getOwner(); 65 bool isLocked(); 66 unsigned int getFlags(); 67 68 void setName(QString value); 69 void setOwner(int value); 70 void setLocked(bool locked); 71 void setFlags(unsigned int value); 72 73 private: 74 snd_seq_queue_info_t* m_Info; 75 }; 76 77 /** 78 * Queue status container. 79 * 80 * This class is used to retrieve some status information from an ALSA queue. 81 */ 82 class DRUMSTICK_EXPORT QueueStatus 83 { 84 friend class MidiQueue; 85 86 public: 87 QueueStatus(); 88 QueueStatus(const QueueStatus& other); 89 explicit QueueStatus(snd_seq_queue_status_t* other); 90 virtual ~QueueStatus(); 91 QueueStatus* clone(); 92 QueueStatus& operator=(const QueueStatus& other); 93 int getInfoSize() const; 94 95 int getId(); 96 int getEvents(); 97 const snd_seq_real_time_t* getRealtime(); 98 unsigned int getStatusBits(); 99 bool isRunning(); 100 double getClockTime(); 101 snd_seq_tick_time_t getTickTime(); 102 103 private: 104 snd_seq_queue_status_t* m_Info; 105 }; 106 107 /** 108 * Queue tempo container. 109 * 110 * This class is used to hold some tempo properties of an ALSA queue object. 111 * The queue's resolution defines the meaning of the musical time, in ticks. It 112 * is expressed in PPQ (parts per quarter), or ticks in a quarter note (crotchet). 113 * The nominal tempo is usually expressed in BPM (beats per minute), or Maelzel 114 * metronome units. It can be also given in microseconds per beat. The tempo skew 115 * factor is given as two integer numbers: skew value and skew base, being the 116 * factor the quotient of both quantities = value / base. Currently (ALSA <= 1.0.20) 117 * you can only use the base constant 0x10000 (decimal 65536). 118 */ 119 class DRUMSTICK_EXPORT QueueTempo 120 { 121 friend class MidiQueue; 122 123 public: 124 QueueTempo(); 125 QueueTempo(const QueueTempo& other); 126 explicit QueueTempo(snd_seq_queue_tempo_t* other); 127 virtual ~QueueTempo(); 128 QueueTempo* clone(); 129 QueueTempo& operator=(const QueueTempo& other); 130 int getInfoSize() const; 131 132 int getId(); 133 int getPPQ(); 134 unsigned int getSkewValue(); 135 unsigned int getSkewBase(); 136 unsigned int getTempo(); 137 void setPPQ(int value); 138 void setSkewValue(unsigned int value); 139 void setTempo(unsigned int value); 140 141 float getNominalBPM(); 142 float getRealBPM(); 143 void setTempoFactor(float value); 144 void setNominalBPM(float value); 145 146 protected: 147 void setSkewBase(unsigned int value); 148 149 private: 150 snd_seq_queue_tempo_t* m_Info; 151 }; 152 153 /** 154 * Queue timer container. 155 * 156 * This class is used to hold some properties about the Timer used with an ALSA 157 * queue object. 158 */ 159 class DRUMSTICK_EXPORT QueueTimer 160 { 161 friend class MidiQueue; 162 163 public: 164 QueueTimer(); 165 QueueTimer(const QueueTimer& other); 166 explicit QueueTimer(snd_seq_queue_timer_t* other); 167 virtual ~QueueTimer(); 168 QueueTimer* clone(); 169 QueueTimer& operator=(const QueueTimer& other); 170 int getInfoSize() const; 171 172 int getQueueId(); 173 snd_seq_queue_timer_type_t getType(); 174 const snd_timer_id_t* getId(); 175 unsigned int getResolution(); 176 void setType(snd_seq_queue_timer_type_t value); 177 void setId(snd_timer_id_t* value); 178 void setId(const TimerId& id); 179 void setResolution(unsigned int value); 180 181 private: 182 snd_seq_queue_timer_t* m_Info; 183 }; 184 185 /** 186 * Queue management. 187 * 188 * This class represents an ALSA sequencer queue object. 189 */ 190 class DRUMSTICK_EXPORT MidiQueue : public QObject 191 { 192 Q_OBJECT 193 public: 194 explicit MidiQueue(MidiClient* seq, QObject* parent = nullptr); 195 MidiQueue(MidiClient* seq, const QueueInfo& info, QObject* parent = nullptr); 196 MidiQueue(MidiClient* seq, const QString name, QObject* parent = nullptr); 197 MidiQueue(MidiClient* seq, const int queue_id, QObject* parent = nullptr); 198 virtual ~MidiQueue(); 199 getId()200 int getId() const { return m_Id; } 201 void start(); 202 void stop(); 203 void continueRunning(); 204 void clear(); 205 void setTickPosition(snd_seq_tick_time_t pos); 206 void setRealTimePosition(snd_seq_real_time_t* pos); 207 QueueInfo& getInfo(); 208 QueueStatus& getStatus(); 209 QueueTempo& getTempo(); 210 QueueTimer& getTimer(); 211 int getUsage(); 212 void setInfo(const QueueInfo& value); 213 void setTempo(const QueueTempo& value); 214 void setTimer(const QueueTimer& value); 215 void setUsage(int used); 216 217 private: 218 bool m_allocated; 219 int m_Id; 220 MidiClient* m_MidiClient; 221 QueueInfo m_Info; 222 QueueTempo m_Tempo; 223 QueueTimer m_Timer; 224 QueueStatus m_Status; 225 }; 226 227 /** @} */ 228 229 }} /* namespace drumstick::ALSA */ 230 231 #endif //DRUMSTICK_ALSAQUEUE_H 232