mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 00:17:06 +00:00
Add MIDI interface classes
This commit is contained in:
@@ -45,7 +45,7 @@ struct IAudioVoiceEngine
|
||||
virtual void pumpAndMixVoices()=0;
|
||||
|
||||
/** Get list of MIDI devices found on system */
|
||||
virtual std::vector<std::string> enumerateMIDIDevices() const=0;
|
||||
virtual std::vector<std::pair<std::string, std::string>> enumerateMIDIDevices() const=0;
|
||||
|
||||
/** Create ad-hoc MIDI in port and register with system */
|
||||
virtual std::unique_ptr<IMIDIIn> newVirtualMIDIIn()=0;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BOO_IMIDIPORT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
43
include/boo/audiodev/IMIDIReader.hpp
Normal file
43
include/boo/audiodev/IMIDIReader.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef BOO_IMIDIREADER_HPP
|
||||
#define BOO_IMIDIREADER_HPP
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class IMIDIReader
|
||||
{
|
||||
public:
|
||||
virtual void noteOff(uint8_t chan, uint8_t key, uint8_t velocity)=0;
|
||||
virtual void noteOn(uint8_t chan, uint8_t key, uint8_t velocity)=0;
|
||||
virtual void notePressure(uint8_t chan, uint8_t key, uint8_t pressure)=0;
|
||||
virtual void controlChange(uint8_t chan, uint8_t control, uint8_t value)=0;
|
||||
virtual void programChange(uint8_t chan, uint8_t program)=0;
|
||||
virtual void channelPressure(uint8_t chan, uint8_t pressure)=0;
|
||||
virtual void pitchBend(uint8_t chan, int16_t pitch)=0;
|
||||
|
||||
virtual void allSoundOff(uint8_t chan)=0;
|
||||
virtual void resetAllControllers(uint8_t chan)=0;
|
||||
virtual void localControl(uint8_t chan, bool on)=0;
|
||||
virtual void allNotesOff(uint8_t chan)=0;
|
||||
virtual void omniMode(uint8_t chan, bool on)=0;
|
||||
virtual void polyMode(uint8_t chan, bool on)=0;
|
||||
|
||||
virtual void sysex(const void* data, size_t len)=0;
|
||||
virtual void timeCodeQuarterFrame(uint8_t message, uint8_t value)=0;
|
||||
virtual void songPositionPointer(uint16_t pointer)=0;
|
||||
virtual void songSelect(uint8_t song)=0;
|
||||
virtual void tuneRequest()=0;
|
||||
|
||||
virtual void startSeq()=0;
|
||||
virtual void continueSeq()=0;
|
||||
virtual void stopSeq()=0;
|
||||
|
||||
virtual void reset()=0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_IMIDIREADER_HPP
|
||||
32
include/boo/audiodev/MIDIDecoder.hpp
Normal file
32
include/boo/audiodev/MIDIDecoder.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BOO_MIDIDECODER_HPP
|
||||
#define BOO_MIDIDECODER_HPP
|
||||
|
||||
#include "boo/audiodev/IMIDIReader.hpp"
|
||||
#include "boo/audiodev/IMIDIPort.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class MIDIDecoder
|
||||
{
|
||||
IMIDIReader& m_out;
|
||||
uint8_t m_status = 0;
|
||||
|
||||
struct ReadController
|
||||
{
|
||||
IMIDIIn& m_in;
|
||||
bool readByte(uint8_t& a);
|
||||
bool read2Bytes(uint8_t& a, uint8_t& b);
|
||||
bool readBuffer(void* buf, size_t len);
|
||||
ReadController(IMIDIIn& in) : m_in(in) {}
|
||||
} m_readControl;
|
||||
uint32_t _readContinuedValue(uint8_t a);
|
||||
public:
|
||||
MIDIDecoder(IMIDIIn& in, IMIDIReader& out) : m_readControl(in), m_out(out) {}
|
||||
bool receiveBytes();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_MIDIDECODER_HPP
|
||||
50
include/boo/audiodev/MIDIEncoder.hpp
Normal file
50
include/boo/audiodev/MIDIEncoder.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef BOO_MIDIENCODER_HPP
|
||||
#define BOO_MIDIENCODER_HPP
|
||||
|
||||
#include "boo/audiodev/IMIDIReader.hpp"
|
||||
#include "boo/audiodev/IMIDIPort.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
template <class Sender>
|
||||
class MIDIEncoder : public IMIDIReader
|
||||
{
|
||||
Sender& m_sender;
|
||||
uint8_t m_status = 0;
|
||||
void _sendMessage(const uint8_t* data, size_t len);
|
||||
void _sendContinuedValue(uint32_t val);
|
||||
public:
|
||||
MIDIEncoder(Sender& sender) : m_sender(sender) {}
|
||||
|
||||
void noteOff(uint8_t chan, uint8_t key, uint8_t velocity);
|
||||
void noteOn(uint8_t chan, uint8_t key, uint8_t velocity);
|
||||
void notePressure(uint8_t chan, uint8_t key, uint8_t pressure);
|
||||
void controlChange(uint8_t chan, uint8_t control, uint8_t value);
|
||||
void programChange(uint8_t chan, uint8_t program);
|
||||
void channelPressure(uint8_t chan, uint8_t pressure);
|
||||
void pitchBend(uint8_t chan, int16_t pitch);
|
||||
|
||||
void allSoundOff(uint8_t chan);
|
||||
void resetAllControllers(uint8_t chan);
|
||||
void localControl(uint8_t chan, bool on);
|
||||
void allNotesOff(uint8_t chan);
|
||||
void omniMode(uint8_t chan, bool on);
|
||||
void polyMode(uint8_t chan, bool on);
|
||||
|
||||
void sysex(const void* data, size_t len);
|
||||
void timeCodeQuarterFrame(uint8_t message, uint8_t value);
|
||||
void songPositionPointer(uint16_t pointer);
|
||||
void songSelect(uint8_t song);
|
||||
void tuneRequest();
|
||||
|
||||
void startSeq();
|
||||
void continueSeq();
|
||||
void stopSeq();
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BOO_MIDIENCODER_HPP
|
||||
Reference in New Issue
Block a user