drumstick 0.5.0
drumstickcommon.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2010, 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 <QApplication>
27#include <QtDebug>
28
29extern "C" {
30#include <alsa/asoundlib.h>
31}
32
41namespace drumstick {
42
46typedef quint8 MidiByte;
47
54class DRUMSTICK_EXPORT SequencerError
55{
56public:
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
97private:
98 QString m_location;
99 int m_errCode;
100};
101
110inline 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
127inline 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
155const QString LIBRARY_VERSION(SND_LIB_VERSION_STR);
156
157} /* namespace drumstick */
158
161#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.