drumstick  1.1.3
drumstickcommon.h
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2019, 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
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef DRUMSTICK_DRUMSTICKCOMMON_H
20 #define DRUMSTICK_DRUMSTICKCOMMON_H
21 
22 #include "macros.h"
23 #include <qglobal.h>
24 #include <QString>
25 #include <QCoreApplication>
26 #include <QtDebug>
27 
28 extern "C" {
29 #include <alsa/asoundlib.h>
30 }
31 
40 namespace drumstick {
41 
45 typedef quint8 MidiByte;
46 
53 class DRUMSTICK_EXPORT SequencerError
54 {
55 public:
61  SequencerError(QString const& s, int rc) :
62  m_location(s), m_errCode(rc) {}
63 
67  virtual ~SequencerError() {}
68 
73  const QString qstrError() const
74  {
75  return QString(snd_strerror(m_errCode));
76  }
77 
82  int code() const
83  {
84  return m_errCode;
85  }
86 
91  const QString& location() const
92  {
93  return m_location;
94  }
95 
96 private:
97  QString m_location;
98  int m_errCode;
99 };
100 
109 inline int checkErrorAndThrow(int rc, const char *where)
110 {
111  if (rc < 0) {
112  qDebug() << "Error code:" << rc << "(" << snd_strerror(rc) << ")";
113  qDebug() << "Location:" << where;
114  throw SequencerError(QString(where), rc);
115  }
116  return rc;
117 }
118 
126 inline int checkWarning(int rc, const char *where)
127 {
128  if (rc < 0) {
129  qWarning() << "Exception code:" << rc << "(" << snd_strerror(rc) << ")";
130  qWarning() << "Location:" << where;
131  }
132  return rc;
133 }
134 
139 #define CHECK_ERROR(x) (checkErrorAndThrow((x),__PRETTY_FUNCTION__))
140 
145 #define CHECK_WARNING(x) (checkWarning((x),__PRETTY_FUNCTION__))
146 
154 const QString LIBRARY_VERSION(SND_LIB_VERSION_STR);
155 
156 } /* namespace drumstick */
157 
160 #endif /*DRUMSTICK_DRUMSTICKCOMMON_H*/
drumstick::checkWarning
int checkWarning(int rc, const char *where)
Check the error code for warning errors.
Definition: drumstickcommon.h:126
drumstick::checkErrorAndThrow
int checkErrorAndThrow(int rc, const char *where)
Checks the error code for severe errors.
Definition: drumstickcommon.h:109
macros.h
drumstick::SequencerError::location
const QString & location() const
Gets the location of the error code as provided in the constructor.
Definition: drumstickcommon.h:91
drumstick::SequencerError
Class used to report errors from the ALSA sequencer.
Definition: drumstickcommon.h:54
drumstick::SequencerError::~SequencerError
virtual ~SequencerError()
Destructor.
Definition: drumstickcommon.h:67
drumstick::LIBRARY_VERSION
const QString LIBRARY_VERSION(SND_LIB_VERSION_STR)
ALSA library version as a constant string.
drumstick::SequencerError::qstrError
const QString qstrError() const
Gets the human readable error message from the error code.
Definition: drumstickcommon.h:73
drumstick::SequencerError::SequencerError
SequencerError(QString const &s, int rc)
Constructor.
Definition: drumstickcommon.h:61
drumstick::SequencerError::code
int code() const
Gets the numeric error code.
Definition: drumstickcommon.h:82
drumstick::MidiByte
quint8 MidiByte
8-bit unsigned number to be used as a MIDI message parameter
Definition: drumstickcommon.h:45