Welcome Guest, you are in: Login

EventIDE Wiki

RSSRSS

Navigation




Search the wiki


PoweredBy

Page History: MIDI Input Element

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2013/06/09 20:13


Element Icon MIDI Input
Info
Category: Behavior Control AddIn: Base Elements
Creator: OkazoLab Team Scope: Parent Event
Owns Snippets: Trigger Usage: Snippets

The MidiInput allows to read an input of various MIDI devices connected to a PC computer. MIDI is a commonly-accepted protocol for communication with digital musical instruments, like MIDI piano keyboards. The MIDI Input element can record a instrumental music played in real-time as a sequence of notes.
The element is proposed for experiments, where participant's input is produced by playing a music on MIDI compatible instruments.


Description

On onset of the parent event the MIDI input element starts to read a real-time input of the selected MIDI Device and record all played notes and other events. Recorded information about a single note includes the MIDI channel number, note name, playback start time, duration, octave number, note's sound frequency and button press velocity (or volume). The element can also detect presses of the control buttons, e.g. program change by reading the low-level MIDI events. The recorded notes and events can be easily accessed in code snippets, used for a flow control in experiment or be just logged.

Examples

 Traditional note signs and corresponding  element's note names  and sound frequencies

Traditional note signs and corresponding
element's note names
and sound frequencies


Example of single note info, recorded by the element:

MIDI Channel: 0
Note: C
Octave: -5
Time: 307 ms
Duration: 562 ms
Frequency: 8.18 Hz
Press Velocity: 45


Practical Use

Technique 1: Logging all MIDI input over a period of time

  1. Add new MIDI input element into the event where you plan to record notes played by a participant
  2. Select the input MIDI device via MIDI Device property. The device has to be connected to PC and turn on
  3. Choose whether you want to record all low-level MIDI events or just MIDI notes
  4. Add a proxy variable on the MIDI Notes property. After the parent event ends, the proxy variable will returns all played notes as an array of clMIDINote structs
  5. Read the MIDI notes array and record it into Report or into a custom file, like in the following snippet:
     // 
    
    for (int i=0;i<MIDINotes.Length;i++)
    {
    Report=Report+MIDINotes[i].Note+";"+MIDINotes[i].Octave+";"+MIDINotes[i].StartTime+";"+MIDINotes[i].Duration+"\n\r"; /// record the note info into Report
    }

    There is no need to clean up the array because the MIDI Notes property is automatically reset on the next onset on the parent event

Technique 2: Detecting a time of the first played note or pressed piano button

  1. Add new MIDI input element into the event where you plan to record a note played by a participant
  2. Select the input MIDI device via MIDI Device property. The device has to be connected to PC and turn on
  3. Choose whether you want to detect a note (after button release) or button press. In the latter case, change the Triggering Mode to "On MIDI event"
  4. Add proxy variables on the Last Note or Last Event property Is Triggered property. You can use Is Triggered as the event end condition via conditional flow route.
  5. Write a recording code to the Triggered snippet of the MIDI Input element. The code may look like this:
      // if you want to detect a note
    
    Report=Report+LastNote.Name+";"+LastNote.Octave+";"+LastNote.StartTime+";"+LastNote.Duration+"\n\r";

    or
     // if you want to detect an initial press of piano button
    
    if ((LastEvent.Name=="NoteOn")&&(LastEvent.Data2>0)) /// select only the 'button-down' events
    Report=Report+LastEvent.Name+";"+LastEvent.MIDIChannel+";"+LastEvent.Time+";"+LastNote.Data1+";"+LastNote.Data2+"\n\r";

    The code will be executed when an incoming note or piano button press is detected. Instruct participants to do not press several buttons simultaneously because, only the last one will be detected by the given technique.

Element actions aligned with the parent event

The elements resets the following properties on each onset of the parent event.
  1. MIDINotes
  2. Last Note
  3. MIDIEvents
  4. Last Event
  5. Triggering Time
  6. Is Triggered

Properties

Generic Properties

NameDescriptionAttributesValue TypeProxy Reflex
Settings
MIDI DeviceDefines a MIDI device that sends an input to this element. System.Enum
Buffer SizeDefines the size of the circular internal buffer that holds an MIDI input (notes and events) at runtime. When all MIDI input has to be recorded the value should be greater than the expected overall length of input in notes or events.System.Int32
Triggering ModeDefines whether the element is triggered by every new low-level MIDI event or only by a new noteSystem.Enum
Test MIDI inputBrings a dialog window that monitors the input of the selected MIDI device for testing purpose System.Int32
Runtime Input
MIDI NotesReturns a runtime array of all MIDI notes received since the onset of the parent event. The last array element corresponds to the newest note. The current length of the array can be obtained by the .Length field. The array resets on each onset of the parent event FORMATTER ERROR (Snippet Not Found) clMIDINote[]
Last NoteReturns the newest note received from the MIDI device. FORMATTER ERROR (Snippet Not Found) clMIDINote
MIDI EventsReturns a runtime array of all low-level MIDI events received since the onset of the parent event. The last array element corresponds to the newest event. The current length of the array can be obtained by the .Length field. The array resets on each onset of the parent event FORMATTER ERROR (Snippet Not Found) clMIDIEvent[]
Last EventReturns the newest event received from the MIDI device. FORMATTER ERROR (Snippet Not Found) clMIDIEvent
Runtime Status
Triggering TimeIndicates the latest event time when the element was triggered (in ms elapsed since activation of the parent event)FORMATTER ERROR (Snippet Not Found) clTime
Is TriggeredIndicates that the element has been triggered at least once since the onset of the parent event FORMATTER ERROR (Snippet Not Found) System.Boolean

+=== Properties inherited from clElement === Inherited properties of clElement
NameDescriptionConstraintsValue TypeUpon Change
Control
Is EnabledIf set to false the element is completely omitted when the experiment is run.Boolean
TitleTitle of the element.String

ScrewTurn Wiki version 5.2.0.8. Some of the icons created by FamFamFam.