MIDI
This class specifies primary parameters in the MIDI Player utility program. The parameters entered in the unique object of this class are shared by both the in-process and the external process program modules.
Each Project Model should contain one object derived from this class for the MIDI Player program to function properly. When more than one object are created, the external process MIDI player takes only the first one into account. The parts derived from the Channel component class should all refer to the first object of this class; otherwise, the MIDI data will not be fetched and distributed correctly.
Although the users only need to pay attention to the first three attributes of this class, we list out all of them here for developers to understand how this class is implemented. We could have set the scopes of the attributes beyond the first three as Hidden so that the users would not be able to see them unless they could enter a service session with a password supplied by the developer -- a feature in the SansGUI Run-Time Environment.
MIDI File Name (cFileName): The MIDI file to be played. Use the Input Assistant from the right click context menu and click on the <File / Dir>... button to locate the MIDI file with the File Locator.
Unique Name for Shared Memroy (cShareName): Enter a unique name to identify the shared memory to be used by both in-process and external process program modules. The name can be any character string.
Sampling Interval (fInterval): The delay time between two samples. This is only used by the in-process program, which fetches data from the external process program via the shared memory. We simply call the Sleep system function to delay the process. No real-time response or timer is used here. You can also enter the value 0 to indicate no delay -- just sample the data in the shared memory as fast as your computer system can.
Current Sampling Time (fTime): The time lapse (simulated) from the start of the in-process program. The user does not have to reset it because it will be set to 0 at each run of the in-process program. It is not in real-time because our implementation simply calls the Win32 Sleep routine and adds Sampling Interval to this time register.
Shared Memory Handle (iHandle): This is a handle returned from Win32 library routines. It is used only by the in-process program to access the shared memory.
Shared Memory Pointer (iMemory): The address of the shared memory. The pointer is obtained by the in-process program during the initialization procedure. It is dereferenced in the in-process program, which then accesses the 2-integer shared memory contents -- one for the MIDI channel number and the other for the MIDI data.
Current MIDI Channel (iChannel): An integer to store the MIDI channel number of the current MIDI event being sampled. The value is obtained from the shared memory and is updated at each sampling cycle.
Current MIDI Data (iData): An integer to store the MIDI data of the current MIDI event being sampled. The value is obtained from the shared memory and is updated at each sampling cycle.
Initialization (SG_xInit): obtains the shared memory created by the external process program module and initializes Shared Memory Handle and Shared Memory Pointer accordingly. Also, reset the Current Sampling Time.
Pre-Evaluation (SG_xPreEval): fetches the channel number and data from the MIDI event recorded in the shared memory by the external process program. When the channel number is negative (-1), it means the MIDI playing has been terminated.
Post-Evaluation (SG_xPostEval): advances the simulated clock. If the Sampling Interval is 0, it simply add 1 millisecond to the Current Sampling Time as an indicator; otherwise, it calls the Win32 Sleep routine to implement the delay.
End Run (SG_xEndRun): cleans up the shared memory resources at the in-process program side. It also checks the SG_STAT_STOP flag to give the user a message when the in-process program is stopped by the user, not by the end of the MIDI playing.
A supporting function get_MIDI_Channel_Data is added to the Collection.MIDI class for other objects, especially Channel components, to obtain channel number and data through the reference object of this class. Please see the source code in the distribution for details.
Consult the Developer's Corner for an overview of the MIDI Player program structure.
See Class Channel for the component class that access the reference object derived from this class.
MIDI Player for SansGUI Version 1.0
Copyright © 2002-2003 ProtoDesign, Inc. All rights reserved.