Chris@559: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@559: 
Chris@559: /*
Chris@559:     Sonic Visualiser
Chris@559:     An audio file viewer and annotation editor.
Chris@559:     Centre for Digital Music, Queen Mary, University of London.
Chris@559:     This file copyright 2006-2009 Chris Cannam and QMUL.
Chris@559:     
Chris@559:     This program is free software; you can redistribute it and/or
Chris@559:     modify it under the terms of the GNU General Public License as
Chris@559:     published by the Free Software Foundation; either version 2 of the
Chris@559:     License, or (at your option) any later version.  See the file
Chris@559:     COPYING included with this distribution for more information.
Chris@559: */
Chris@559: 
Chris@1581: #ifndef SV_MIDI_INPUT_H
Chris@1581: #define SV_MIDI_INPUT_H
Chris@559: 
Chris@559: #include <QObject>
Chris@559: #include "MIDIEvent.h"
Chris@559: 
Chris@560: #include <vector>
Chris@560: #include "base/RingBuffer.h"
Chris@567: #include "base/FrameTimer.h"
Chris@560: 
Chris@561: class RtMidiIn;
Chris@559: 
Chris@559: class MIDIInput : public QObject
Chris@559: {
Chris@559:     Q_OBJECT
Chris@559: 
Chris@559: public:
Chris@567:     MIDIInput(QString name, FrameTimer *timer);
Chris@559:     virtual ~MIDIInput();
Chris@559: 
Chris@561:     bool isOK() const { return m_rtmidi != 0; }
Chris@559: 
Chris@559:     bool isEmpty() const { return getEventsAvailable() == 0; }
Chris@929:     int getEventsAvailable() const { return m_buffer.getReadSpace(); }
Chris@559:     MIDIEvent readEvent();
Chris@559: 
Chris@559: signals:
Chris@559:     void eventsAvailable();
Chris@559: 
Chris@559: protected:
Chris@561:     RtMidiIn *m_rtmidi;
Chris@567:     FrameTimer *m_frameTimer;
Chris@559: 
Chris@561:     static void staticCallback(double, std::vector<unsigned char> *, void *);
Chris@559:     void callback(double, std::vector<unsigned char> *);
Chris@559: 
Chris@559:     void postEvent(MIDIEvent);
Chris@559:     RingBuffer<MIDIEvent *> m_buffer;
Chris@559: };
Chris@559: 
Chris@559: #endif
Chris@559: