All pastes #39070 Raw Edit

Mine

public text v1 · immutable
#39070 ·published 2006-01-29 23:11 UTC
rendered paste body
#ifdef USE_ALSA_MIDI
#include <alsa/asoundlib.h>
#endif

#if __APPLE__
#include <CoreMIDI/MIDIServices.h>
#endif

class MidiEvent
{
public:
        enum type{NONE,ON,OFF,AFTERTOUCH,PARAMETER,CHANNELPRESSURE,PITCHBEND};

        MidiEvent() {m_Type=NONE;}
        MidiEvent(type t, int note, float v)
                {m_Type=t; m_Note=note; m_Volume=v;}

        type GetType() const {return m_Type;}
        float GetVolume() const {return m_Volume;}
        int GetNote() const {return m_Note;}
private:
        float m_Volume;
        type  m_Type;
        int   m_Note;
};

class MidiDevice
{
public:
        ~MidiDevice();

        enum Type{READ,WRITE};
        static void Init(const string &name, Type t);
        static void SetDeviceName(string s) {
               #ifdef USE_OSS_MIDI
               m_DeviceName=s;
               #endif
        }
        static MidiDevice *Get()      { return m_Singleton; }
        static void PackUpAndGoHome() { if (m_Singleton) delete m_Singleton; m_Singleton=NULL; }

        MidiEvent GetEvent(int Device);
        void SendEvent(int Device,const MidiEvent &Event);

        void SetPoly(int s) { m_Poly=s; }

        float GetClock() { return m_Clock; }

private:
        MidiDevice(Type t);

        int  m_Poly;
        float m_Clock;
        int   m_ClockCount;

        queue<MidiEvent> m_EventVec[16];

        static MidiDevice *m_Singleton;

        pthread_t        m_MidiReader;
        pthread_mutex_t* m_Mutex;

        static string m_AppName;
#ifdef USE_ALSA_MIDI
        static void *MidiReaderCallback (void *o) { ((MidiDevice*)o)->AlsaCollectEvents(); return NULL; }
        void AlsaCollectEvents();
        void AlsaSendEvent(int Device, const MidiEvent &Event);

        void AlsaClose ();

        //snd_seq_t *seq_handle;

        //I appears that ALsa does not support both a read and write handle
        //so we must have two handle one for each mode
        snd_seq_t *seq_rhandle;
        snd_seq_t *seq_whandle;

        void AlsaOpen();
#endif
#ifdef USE_OSS_MIDI
        static void *MidiReaderCallback (void *o) { ((MidiDevice*)o)->OssCollectEvents(); return NULL; }
        void OssCollectEvents();