![]() |
Mixxx
|
00001 00007 /*************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #ifndef SOUNDMANAGERUTIL_U 00017 #define SOUNDMANAGERUTIL_U 00018 00019 #include <QString> 00020 #include <QtXml> 00021 #include <QMutex> 00022 00023 #include "defs.h" // for CSAMPLE (???) 00024 00030 class ChannelGroup { 00031 public: 00032 ChannelGroup(unsigned char channelBase, unsigned char channels); 00033 unsigned char getChannelBase() const; 00034 unsigned char getChannelCount() const; 00035 bool operator==(const ChannelGroup &other) const; 00036 bool clashesWith(const ChannelGroup &other) const; 00037 unsigned int getHash() const; 00038 private: 00039 unsigned char m_channelBase; // base (first) channel used on device 00040 unsigned char m_channels; // number of channels used (s/b 2 in most cases) 00041 }; 00042 00049 class AudioPath { 00050 public: 00051 // XXX if you add a new type here, be sure to add it to the various 00052 // methods including getStringFromType, isIndexed, getTypeFromInt, 00053 // channelsNeededForType (if necessary), the subclasses' getSupportedTypes 00054 // (if necessary), etc. -- bkgood 00055 enum AudioPathType { 00056 MASTER, 00057 HEADPHONES, 00058 DECK, 00059 VINYLCONTROL, 00060 MICROPHONE, 00061 EXTPASSTHROUGH, 00062 INVALID, // if this isn't last bad things will happen -bkgood 00063 }; 00064 AudioPath(unsigned char channelBase, unsigned char channels); 00065 AudioPathType getType() const; 00066 ChannelGroup getChannelGroup() const; 00067 unsigned char getIndex() const; 00068 bool operator==(const AudioPath &other) const; 00069 unsigned int getHash() const; 00070 bool channelsClash(const AudioPath &other) const; 00071 QString getString() const; 00072 static QString getStringFromType(AudioPathType type); 00073 static QString getTrStringFromType(AudioPathType type); 00074 static AudioPathType getTypeFromString(QString string); 00075 static bool isIndexed(AudioPathType type); 00076 static AudioPathType getTypeFromInt(int typeInt); 00077 static unsigned char channelsNeededForType(AudioPathType type); 00078 protected: 00079 virtual void setType(AudioPathType type) = 0; 00080 AudioPathType m_type; 00081 ChannelGroup m_channelGroup; 00082 unsigned char m_index; 00083 }; 00084 00091 class AudioOutput : public AudioPath { 00092 public: 00093 AudioOutput(AudioPathType type = INVALID, unsigned char channelBase = 0, 00094 unsigned char index = 0); 00095 QDomElement toXML(QDomElement *element) const; 00096 static AudioOutput fromXML(const QDomElement &xml); 00097 static QList<AudioPathType> getSupportedTypes(); 00098 protected: 00099 void setType(AudioPathType type); 00100 }; 00101 00108 class AudioInput : public AudioPath { 00109 public: 00110 AudioInput(AudioPathType type = INVALID, unsigned char channelBase = 0, 00111 unsigned char index = 0); 00112 QDomElement toXML(QDomElement *element) const; 00113 static AudioInput fromXML(const QDomElement &xml); 00114 static QList<AudioPathType> getSupportedTypes(); 00115 protected: 00116 void setType(AudioPathType type); 00117 }; 00118 00119 class AudioSource { 00120 public: 00121 virtual const CSAMPLE* buffer(AudioOutput output) const = 0; 00122 virtual void onOutputConnected(AudioOutput output) { Q_UNUSED(output); }; 00123 virtual void onOutputDisconnected(AudioOutput output) { Q_UNUSED(output); }; 00124 }; 00125 00126 class AudioDestination { 00127 public: 00128 virtual void receiveBuffer(AudioInput input, const short* pBuffer, unsigned int iNumFrames) = 0; 00129 virtual void onInputConnected(AudioInput input) { Q_UNUSED(input); }; 00130 virtual void onInputDisconnected(AudioInput input) { Q_UNUSED(input); }; 00131 }; 00132 00133 typedef AudioPath::AudioPathType AudioPathType; 00134 00135 // globals for QHash 00136 unsigned int qHash(const ChannelGroup &group); 00137 unsigned int qHash(const AudioOutput &output); 00138 unsigned int qHash(const AudioInput &input); 00139 00140 #endif