Welcome
Guest
, you are in:
<root>
Elements
•
Login
EventIDE Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
Administration
File Management
Create Account
Search the wiki
Back
MIDI Input Element
Modified on 2018/08/03 01:33
by
Administrator
Categorized as
Base Elements
,
Elements
,
Input Registration
<div style="margin-right: 10px; margin-left: 16px; margin-bottom:10px; float: right; width: 500px; overflow: hidden; height: auto; padding: 0px; background: #fafafa; background: -webkit-gradient(linear, left top, left bottom, from(#fbfbfb), to(#fafafa));background: -moz-linear-gradient(top, #fbfbfb, #fafafa);border: 1px dashed #ddd;box-shadow: 0 0 0 3px #fff, 0 0 0 5px #ddd, 0 0 0 10px #fff, 0 0 2px 10px #eee;"> == Summary == {s:Element Info Panel | title=MIDI Input | category=Input Registration | icon=[image|Element Icon|{UP(MIDI-Input-Element)}MIDI-Input-Element-Icon.png] | author= OkazoLab | addin= Base Layer | scope= Parent event | usage= Snippets | ownsnippets= None } == Properties == {| |- ! Name ! Description ! Constraints ! Type ! On<br/>runtime<br/>change |- | colspan="5" bgcolor="#AADDDDD" | Settings |- | MIDI Device | Defines a MIDI device that sends an input to this element | {s:atDesign} | Int32 | |- | Buffer Size | Defines 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. | {s:atDesign} | Int32 | |- | Triggering Mode | Defines whether the element is triggered by every MIDI event (including e.g. contoller buttons) or only by a new note | {s:atDesign} | enMIDI.. | |- | Test MIDI Input | Brings a dialog window that monitors the input of the selected MIDI device for testing purpose | {s:atDesign} | Boolean | |- | colspan="5" bgcolor="#AADDDDD" | Runtime Input |- | MIDI Notes | Returns 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 with the each onset of the parent event | {s:atStatus} | clMIDI.. | |- | Newest Note | Returns the newest note received from the MIDI device | {s:atStatus} | clMIDI.. | |- | MIDI Events | Returns a runtime array of all received MIDI events since the onset of the parent event. The built-in type of array elements is clMIDIEvent (the array itself - clMIDIEvent[] ) The last element corresponds to the newest event. The array resets with the each onset of the parent event | {s:atStatus} | clMIDI.. | |- | Newest MIDI Event | Returns the newest event received from the MIDI device | {s:atStatus} | clMIDI.. | |- | colspan="5" bgcolor="#AADDDDD" | Runtime Status |- | Triggering Time | Indicates the latest event time when the element was triggered (in ms elapsed since activation of the parent event) | {s:atStatus} | clTime | |- | Is Triggered | Indicates that the element has been triggered at least once since the onset of the parent event | {s:atNormal} | Boolean | |- | colspan="5" bgcolor="#AADDDDD" | Control |- | Is Enabled | If set to false the element is completely omitted when the experiment is run | {s:atDesign} | Boolean | |- | Title | Title of the element | {s:atDesign} | String | |- |} == == </div> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> <!--*****************************************************************************************************************************************************************************--> '''MIDI Input Element''' allows read and log an input coming from [^http://en.wikipedia.org/wiki/MIDI|MIDI] devices connected to a 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 [http://en.wikipedia.org/wiki/Note|notes]. <br/> The element is proposed for experiments, where participant's input is produced by playing a music on MIDI compatible instruments.<br><br> {TOC} == 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. == Demo video == <iframe width="560" height="315" src="https://www.youtube.com/embed/WR0YknJJ-i8" frameborder="0" allowfullscreen></iframe> == Examples == {| | [imageleft| Traditional note signs and corresponding <br/> element's note names <br/> and sound frequencies |{UP}/pictures/Elements/MIDIInput/sm_Frequency_vs_name.png|{UP}/pictures/Elements/MIDIInput/Frequency_vs_name.png] |} Example of single note info, recorded by the element: MIDI Channel: 0 <br/> Note: C<br/> Octave: -5<br/> Time: 307 ms <br/> Duration: 562 ms <br/> Frequency: 8.18 Hz<br/> Press Velocity: 45<br/> == Practical Use == === Technique 1: Logging all MIDI input over a period of time === # Add new MIDI input element into the event where you plan to record notes played by a participant # Select the input MIDI device via MIDI Device property. The device has to be connected to PC and turn on # Choose whether you want to record all low-level MIDI events or just MIDI notes # Add a [proxy variables|proxy variable] on the MIDI Notes property. After the parent event ends, the proxy variable will returns all played notes as an array of [Built-in data types#clMIDINote|clMIDINote] structs # Read the MIDI notes array and record it into [Report|Report] or into a custom file, like in the following snippet: @@ csharp // 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 === # Add new MIDI input element into the [events|event] where you plan to record a note played by a participant # Select the input MIDI device via MIDI Device property. The device has to be connected to PC and turn on # 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" # 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 routes|flow route]. # Write a recording code to the Triggered snippet of the MIDI Input element. The code may look like this: @@ csharp // if you want to detect a note Report=Report+LastNote.Name+";"+LastNote.Octave+";"+LastNote.StartTime+";"+LastNote.Duration+"\n\r"; @@ or @@ csharp // 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.
Meta Keywords:
Meta Description:
Change Comment:
ScrewTurn Wiki
version 5.2.0.8. Some of the icons created by
FamFamFam
.