drumstick  1.0.2
drumstickcommon.h
Go to the documentation of this file.
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_DRUMSTICKCOMMON_H
00021 #define DRUMSTICK_DRUMSTICKCOMMON_H
00022 
00023 #include "macros.h"
00024 #include <qglobal.h>
00025 #include <QString>
00026 #include <QCoreApplication>
00027 #include <QtDebug>
00028 
00029 extern "C" {
00030 #include <alsa/asoundlib.h>
00031 }
00032 
00041 namespace drumstick {
00042 
00046 typedef quint8 MidiByte;  
00047 
00054 class DRUMSTICK_EXPORT SequencerError
00055 {
00056 public:
00062     SequencerError(QString const& s, int rc) :
00063         m_location(s), m_errCode(rc) {}
00064 
00068     virtual ~SequencerError() {}
00069 
00074     const QString qstrError() const 
00075     {
00076         return QString(snd_strerror(m_errCode));
00077     }
00078 
00083     int code() const 
00084     { 
00085         return m_errCode; 
00086     }
00087     
00092     const QString& location() const 
00093     { 
00094         return m_location; 
00095     }
00096 
00097 private:
00098     QString m_location;
00099     int     m_errCode;
00100 };
00101 
00110 inline int checkErrorAndThrow(int rc, const char *where)
00111 {
00112     if (rc < 0) {
00113         qDebug() << "Error code:" << rc << "(" <<  snd_strerror(rc) << ")";
00114         qDebug() << "Location:" << where;
00115         throw SequencerError(QString(where), rc);
00116     }
00117     return rc;
00118 }
00119 
00127 inline int checkWarning(int rc, const char *where)
00128 {
00129     if (rc < 0) {
00130         qWarning() << "Exception code:" << rc << "(" <<  snd_strerror(rc) << ")";
00131         qWarning() << "Location:" << where;
00132     }
00133     return rc;
00134 }
00135 
00140 #define CHECK_ERROR(x)   (checkErrorAndThrow((x),__PRETTY_FUNCTION__))
00141 
00146 #define CHECK_WARNING(x) (checkWarning((x),__PRETTY_FUNCTION__))
00147 
00155 const QString LIBRARY_VERSION(SND_LIB_VERSION_STR);
00156 
00157 } /* namespace drumstick */
00158 
00161 #endif /*DRUMSTICK_DRUMSTICKCOMMON_H*/