drumstick  1.1.0
drumstickcommon.h
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2016, 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 2 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 along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef DRUMSTICK_DRUMSTICKCOMMON_H
21 #define DRUMSTICK_DRUMSTICKCOMMON_H
22 
23 #include "macros.h"
24 #include <qglobal.h>
25 #include <QString>
26 #include <QCoreApplication>
27 #include <QtDebug>
28 
29 extern "C" {
30 #include <alsa/asoundlib.h>
31 }
32 
41 namespace drumstick {
42 
46 typedef quint8 MidiByte;
47 
54 class DRUMSTICK_EXPORT SequencerError
55 {
56 public:
62  SequencerError(QString const& s, int rc) :
63  m_location(s), m_errCode(rc) {}
64 
68  virtual ~SequencerError() {}
69 
74  const QString qstrError() const
75  {
76  return QString(snd_strerror(m_errCode));
77  }
78 
83  int code() const
84  {
85  return m_errCode;
86  }
87 
92  const QString& location() const
93  {
94  return m_location;
95  }
96 
97 private:
98  QString m_location;
99  int m_errCode;
100 };
101 
110 inline int checkErrorAndThrow(int rc, const char *where)
111 {
112  if (rc < 0) {
113  qDebug() << "Error code:" << rc << "(" << snd_strerror(rc) << ")";
114  qDebug() << "Location:" << where;
115  throw SequencerError(QString(where), rc);
116  }
117  return rc;
118 }
119 
127 inline int checkWarning(int rc, const char *where)
128 {
129  if (rc < 0) {
130  qWarning() << "Exception code:" << rc << "(" << snd_strerror(rc) << ")";
131  qWarning() << "Location:" << where;
132  }
133  return rc;
134 }
135 
140 #define CHECK_ERROR(x) (checkErrorAndThrow((x),__PRETTY_FUNCTION__))
141 
146 #define CHECK_WARNING(x) (checkWarning((x),__PRETTY_FUNCTION__))
147 
155 const QString LIBRARY_VERSION(SND_LIB_VERSION_STR);
156 
157 } /* namespace drumstick */
158 
161 #endif /*DRUMSTICK_DRUMSTICKCOMMON_H*/