Welcome to Midijo’s documentation!

Midijo repository: https://github.com/KaixoCode/Midijo

Documentation

Midi

template<Api api = Unspecified>
class Midijo::Midi

Public Functions

const DeviceInfo &Device(int id) const

Returns device with the given id.

Return

device with id

Parameters
  • id: device id

int DeviceCount() const

Get the device count.

Return

device count

const MidiInformation &Information() const

Get midi information. This call only returns useful information after a device has been opened.

Return

midi information

Error Open(const MidiParameters &settings = MidiParameters{})

Open the midi device.

Return

AlreadyOpen - If the stream is already opened

InUse - If the midi device is already in use

InvalidDevice - If the provided device id is invalid

Fail - If the device failed to open

NoError - If stream opened successfully

Parameters

Error Close()

Close the midi device.

Return

NotOpen - If the stream wasn’t opened

InvalidDevice - If the opened device id has become invalid

Fail - If the device failed to close

NoError - If stream closed successfully

template<Api api = Unspecified>
class Midijo::MidiIn : public Midijo::Midi<Unspecified>

Public Functions

MidiIn()

Constructor

Parameters
  • a: api

template<Api a>
MidiIn<a> &Get()

Get this MidiIn object as a specific api, to expose api specific functions.

Return

this as a midi object for a specific api

void Api(Midijo::Api a)

Set the api.

Parameters
  • api: api

Midijo::Api Api() const

Get the current api of this midi.

Return

api

template<ValidCallback T>
Callback ScopedCallback(T &&callback)

Add a midi event callback. The returned Callback object will remove the callback from when its destructor is called. This behaviour is useful when registering a callback inside an object, because this will automatically remove the callback when the object is destroyed.

Return

callback object

Parameters
  • callback: callback

template<ValidCallback T>
void Callback(T &&callback)

Add a midi event callback.

Parameters
  • callback: callback

void HandleEvents()

Only use this when async is set to false. Handles all the events in the queue.

bool HandleEvent()

Only use this when async is set to false. Handles a single event, returns true when an event was handled.

Return

true if there was an event to handle.

template<Api api = Unspecified>
class Midijo::MidiOut : public Midijo::Midi<Unspecified>

Public Functions

MidiOut()

Constructor

Parameters
  • a: api

template<Api a>
MidiOut<a> &Get()

Get this MidiIn object as a specific api, to expose api specific functions.

Return

this as a midi object for a specific api

void Api(Midijo::Api api)

Set the api.

Parameters
  • api: api

Midijo::Api Api() const

Get the current api of this midi.

Return

api

void Message(const Event &e)

Send a message to the device.

Parameters

Events

struct Midijo::Event

Subclassed by Midijo::Aftertouch, Midijo::CC, Midijo::ChannelAftertouch, Midijo::NoteOff, Midijo::NoteOn, Midijo::PitchBend, Midijo::ProgramChange

Public Functions

void Handle() const

Signal that this event has been handled.

bool Handled() const

Check if this event has been handled.

Return

true when Handle has been called

struct Midijo::NoteOn : public Midijo::Event

Event that fires when you press a midi key.

Public Functions

NoteOn(Midijo::Note note, uint8_t velocity)

Create note on event.

Parameters
  • note: note

  • velocity: velocity

NoteOn(uint8_t raw, uint8_t velocity)

Create note on event.

Parameters
  • raw: raw note number

  • velocity: velocity

Midijo::Note Note() const

Get the midi note that was pressed.

Return

midi note

uint8_t RawNote() const

Get the raw note number.

Return

raw note number

uint8_t Velocity() const

Get the velocity.

Return

velocity

struct Midijo::NoteOff : public Midijo::Event

Event that fires when you release a midi key.

Public Functions

NoteOff(Midijo::Note note, uint8_t velocity)

Create note off event.

Parameters
  • note: note

  • velocity: velocity

NoteOff(uint8_t raw, uint8_t velocity)

Create note off event.

Parameters
  • raw: raw note number

  • velocity: velocity

Midijo::Note Note() const

Get the midi note that was pressed.

Return

midi note

uint8_t RawNote() const

Get the raw note number.

Return

raw note number

uint8_t Velocity() const

Get the velocity.

Return

velocity

struct Midijo::Aftertouch : public Midijo::Event

Event that fires when there is a pressure change press on one of the currently pressed midi keys.

Public Functions

Aftertouch(Midijo::Note note, uint8_t amount)

Create aftertouch event.

Parameters
  • note: note

  • amount: amount

Aftertouch(uint8_t raw, uint8_t amount)

Create aftertouch event.

Parameters
  • raw: raw note number

  • amount: amount

Midijo::Note Note() const

Get the midi note that was pressed.

Return

midi note

uint8_t RawNote() const

Get the raw note number.

Return

raw note number

uint8_t Amount() const

Get the aftertouch amount.

Return

amount

struct Midijo::CC : public Midijo::Event

Event that fires when there is a change in state of one of the controllers.

Public Functions

CC(uint8_t number, uint8_t value)

Create cc event.

Parameters
  • number: number

  • value: value

uint8_t Number() const

Get the cc number that was updated.

Return

cc number

uint8_t Value() const

Get the value of the cc that was updated.

Return

value

struct Midijo::ProgramChange : public Midijo::Event

Event that fires when a program change is requested.

Public Functions

ProgramChange(uint8_t program)

Create program change event.

Parameters
  • program: program

uint8_t Program() const

Get the program.

Return

program

struct Midijo::ChannelAftertouch : public Midijo::Event

Event that fired when the channel aftertouch has been changed.

Public Functions

ChannelAftertouch(uint8_t amount)

Create channel aftertouch event.

Parameters
  • amount: amount

uint8_t Amount() const

Get the aftertouch amount.

Return

amount

struct Midijo::PitchBend : public Midijo::Event

Event that fires when the pitch bend changes.

Public Functions

PitchBend(uint8_t amount)

Create pitch bend event.

Parameters
  • amount: amount

uint16_t Value() const

Get the pitch bend value.

Return

value

Structs

struct Midijo::MidiParameters

Public Members

int device = 0

Midi device id.

int async = true

Asynchronously receive the midi messages.

template<Api api = Unspecified>
struct Midijo::DeviceInfo

Public Members

int id

Device id

std::string name

Device name

Api api

Device api

Enums

enum Midijo::Api

Values:

enumerator Unspecified
enumerator Windows
enumerator DefaultApi
enum Midijo::Error

Values:

enumerator NoError
enumerator NoMemory
enumerator InUse
enumerator InvalidDevice
enumerator NotOpen
enumerator AlreadyOpen
enumerator Fail

Examples

Midi input

#include "Midijo/Midijo.hpp"

using namespace Midijo;

int main()
{
    MidiIn midi;

    // Register a callback for any event type.
    midi.Callback([](const Event& e)
    {
        std::cout <<
            (int)e.byte1 << ", " << (int)e.byte2 << ", " <<
            (int)e.byte3 << ", " << (int)e.byte4 << '\n';
    });

    // Register a callback for a specific event type.
    midi.Callback([](const NoteOn& e)
    {
        std::cout << e.Note() << ", " << e.Velocity() << '\n';
    });

    // Open device with id 0 and start.
    midi.Open({.device = 0 });
    midi.Start();

    // Receive events for 10 seconds.
    std::this_thread::sleep_for(std::chrono::seconds(10));

    // Close the device.
    midi.Close();
}