zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

InMgr.h (1889B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   InMgr.h - MIDI Input Manager
      5   Copyright (C) 2016 Mark McCurry
      6 
      7   This program is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU General Public License
      9   as published by the Free Software Foundation; either version 2
     10   of the License, or (at your option) any later version.
     11 */
     12 #ifndef INMGR_H
     13 #define INMGR_H
     14 
     15 #include <string>
     16 #include "ZynSema.h"
     17 #include "SafeQueue.h"
     18 
     19 namespace zyn {
     20 
     21 enum midi_type {
     22     M_NOTE = 1, // for note
     23     M_CONTROLLER = 2, // for controller
     24     M_PGMCHANGE  = 3, // for program change
     25     M_PRESSURE   = 4, // for polyphonic aftertouch
     26     M_FLOAT_NOTE = 5, // for floating point note
     27     M_FLOAT_CTRL = 6  // for floating point controller
     28 };
     29 
     30 struct MidiEvent {
     31     MidiEvent();
     32     int channel; //the midi channel for the event
     33     int type;    //type=1 for note, type=2 for controller
     34     int num;     //note, controller or program number
     35     int value;   //velocity or controller value
     36     int time;    //time offset of event (used only in jack->jack case at the moment)
     37     float log2_freq;   //type=5,6 for logarithmic representation of note/parameter
     38 };
     39 
     40 //super simple class to manage the inputs
     41 class InMgr
     42 {
     43     public:
     44         static InMgr &getInstance();
     45         ~InMgr();
     46 
     47         void putEvent(MidiEvent ev);
     48 
     49         /**Flush the Midi Queue*/
     50         bool flush(unsigned frameStart, unsigned frameStop);
     51 
     52         bool empty() const;
     53 
     54         bool setSource(std::string name);
     55 
     56         std::string getSource() const;
     57 
     58         void setMaster(class Master *master);
     59 
     60         friend class EngineMgr;
     61     private:
     62         InMgr();
     63         class MidiIn *getIn(std::string name);
     64         SafeQueue<MidiEvent> queue;
     65         mutable ZynSema work;
     66         class MidiIn * current;
     67 
     68         /**the link to the rest of zyn*/
     69         class Master *master;
     70 };
     71 
     72 }
     73 
     74 #endif