EventFromHost

Table of contents

  1. Description
  2. 1. Checking if available
  3. 2. Identify the type of event
  4. 3. Accessing the information
  5. Example

Description

As mentioned before the data received from the host are provided in a per-buffer basis. For each buffer multiple information can be available:

  1. DAW Status at the start of the buffer: Play, Stop, Record, Loop, Tempo, Time Signature, Buffer Position
  2. MIDI Events within the buffer: Note On, Note Off …

These data received from the host are wrapped in the EventFromHost data type and are provided to you in the ITP thread.

In ITP_Deploy.cpp, these events are passed on to you sequentially (whenever available) using the new_event_from_host variable of the Deploy() method.

As mentioned before, you can specify which of these events you want to receive in the ITP thread

To do so, you need to specify the Configs_HostEvents.h file. To learn more about this process, visit [this page]((/docs/v1_0_0/DeploymentStages/ITP/HostEvents)

1. Checking if available

The new_event_from_host variable is an optional variable, as a result before using it, you should always check if it is available

if (new_event_from_host->has_value()) {
    // ... 
}

2. Identify the type of event

There are different types available in the EventFromHost data type.

Event TypeCheck MethodDescription
FirstBufferEventnew_event_from_host->isFirstBufferEvent()Sent at the beginning of the host start.
PlaybackStoppedEventnew_event_from_host->isPlaybackStoppedEvent()Sent when the host stops the playback.
NewBufferEventnew_event_from_host->isNewBufferEvent()Sent at the beginning of every new buffer or when qpm, meter, etc. changes.
NewBarEventnew_event_from_host->isNewBarEvent()Sent at the beginning of every new bar.
NewTimeShiftEventnew_event_from_host->isNewTimeShiftEvent()Sent every N QuarterNotes (as specified in the configs file
NoteOnEventnew_event_from_host->isNoteOnEvent()Sent when a note is played.
NoteOffEventnew_event_from_host->isNoteOffEvent()Sent when a note is stopped.
CCEventnew_event_from_host->isCCEvent()Sent for Control Change events.

3. Accessing the information

Regardless of the type, the following information is always available within the received event:

InformationAccess Method
Event Time (Various Units)new_event_from_host->Time().inSeconds(), new_event_from_host->Time().inSamples(), new_event_from_host->Time().inQuarterNotes()
QPM (Tempo)new_event_from_host->qpm()
Time Signaturenew_event_from_host->numerator(), new_event_from_host->denominator()
Playback Statusnew_event_from_host->isPlaying(), new_event_from_host->isRecording()
Buffer Start Timenew_event_from_host->BufferStartTime().inSeconds()
Buffer End Time (Seconds)new_event_from_host->BufferEndTime().inSamples()
Buffer End Time (Quarter Notes)new_event_from_host->BufferEndTime().inQuarterNotes()
Looping Statusnew_event_from_host->isLooping()
Loop Start and End Times (Quarter Notes)new_event_from_host->loopStart(), new_event_from_host->loopEnd()
Number of Bars Elapsednew_event_from_host->barCount()
Last Bar Positionnew_event_from_host->lastBarPos().inSeconds(), new_event_from_host->lastBarPos().inSamples(), new_event_from_host->lastBarPos().inQuarterNotes(),

The following information is available for NoteOnEvent and NoteOffEvent:

InformationAccess Method
Note Numbernew_event_from_host->getNoteNumber()
Velocitynew_event_from_host->getVelocity()
Channelnew_event_from_host->getChannel()

The following information is available for CCEvent:

InformationAccess Method
CC Numbernew_event_from_host->getCCNumber()
Valuenew_event_from_host->getCCValue()
Channelnew_event_from_host->getChannel()

Example

   if (new_event_from_host.has_value()) {

        if (new_event_from_host->isFirstBufferEvent()) {

        } else if (new_event_from_host->isPlaybackStoppedEvent()) {

        } else if (new_event_from_host->isNewBufferEvent()) {

        } else if (new_event_from_host->isNewBarEvent()) {

        } else if (new_event_from_host->isNewTimeShiftEvent()) {

        } else if (new_event_from_host->isNoteOnEvent()) {
            auto note_n = new_event_from_host->getNoteNumber();
            auto vel =new_event_from_host->getVelocity();
            auto channel = new_event_from_host->getChannel();
            auto time = new_event_from_host->Time().inSeconds();
        } else if (new_event_from_host->isNoteOffEvent()) {
            auto note_n = new_event_from_host->getNoteNumber();
            auto vel =new_event_from_host->getVelocity();
            auto channel = new_event_from_host->getChannel();
        } else if (new_event_from_host->isCCEvent()) {
        }
    }