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
28extern "C" {
29#include <alsa/asoundlib.h>
30}
31
40namespace drumstick {
41
45typedef quint8 MidiByte;
46
53class DRUMSTICK_EXPORT SequencerError
54{
55public:
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
96private:
97 QString m_location;
98 int m_errCode;
99};
100
109inline 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
126inline 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
154const QString LIBRARY_VERSION(SND_LIB_VERSION_STR);
155
156} /* namespace drumstick */
157
160#endif /*DRUMSTICK_DRUMSTICKCOMMON_H*/
Class used to report errors from the ALSA sequencer.
int code() const
Gets the numeric error code.
SequencerError(QString const &s, int rc)
Constructor.
const QString & location() const
Gets the location of the error code as provided in the constructor.
virtual ~SequencerError()
Destructor.
const QString qstrError() const
Gets the human readable error message from the error code.
const QString LIBRARY_VERSION(SND_LIB_VERSION_STR)
ALSA library version as a constant string.
int checkWarning(int rc, const char *where)
Check the error code for warning errors.
quint8 MidiByte
8-bit unsigned number to be used as a MIDI message parameter
int checkErrorAndThrow(int rc, const char *where)
Checks the error code for severe errors.
Drumstick visibility macros.