DxMidi Tutorial - MidiModule project - chapter 2 | |
To follow this tutorial you need :
RealBasic 2 |
|
Project 2 - signing to OMS studio and send notes First, open the midi02.rbp project. It is the OMS connection program. - Verify that OMS is active (report to the OMS installation guide included in this manual), Project window Open the project and examine the items : Menu item : App : Application : Midi : Win: Application Midi client scope Because most of Midi applications needs to sign to Midi at start, and sign out at end, we need to do the same with an "Application" module wich is specific to RealBasic system. it permits to open the program without opening first a window. There will be times when you want just to start application without opening a window ! Make like this to maintain good client relation with the Midi driver, and force application to sign out at the end.
NOTE : OMS has a specific system to prevent crashes because of sign out missing. It lets you reconnect to Midi even after a program crash. Application : "Open" event This procedure executes two methods : Connect_midi is a custom method to connect DxMidi to the driver Application : "Close" event When close is executed, at the end of the program, disconnect_midi, examines Midi connection and sign out to the driver if the connection was active. By this, you are shure that the client has sign out at the end, without any other code elsewhere. Win (window) : Use
Midi module This module maintains ours connect_midi and disconnect_midi methods. Open the module (double-click on it). And see the code. This is the connection code. Just to connect to OMS as a "client". You can see also the global variables (properties of the "Midi" module).
Midi connection This is the OMS_connect code : Let's analyze this code : avail = DxMidiOMSAvail() This method let you know if OMS is ready to be used, or not. It is very important to start with this method because if OMS is not ready, any other method called to OMS interface could create an error in the program. avail contains TRUE if OMS is active. result = DxOMSConnect("dfmm", "spocky3") This time, we try to connect to the OMS Midi port and sign in the studio. This is required to do something more with OMS. If DxOMSConnect is successful, the result contains 0, otherwise, result contains a DxMidi error code.
Get the nodes, and connect the IN and OUT ports if oms_connected = true then We can just get the nodes if oms_connected is true (to preserve from an OMS error in the program. Initialize 2 values for counting the number of IN and OUT nodes in_nodes = 0 First, get the OUT nodes The 0 values indicates to DxOMSGetNodes to get the OUT nodes ports At this time, you don't really know what is in each value between 1 and the number of nodes, but in this example we only use the first value found. If result is 0, then sorry but there is no OUT node connected in your studio. select_out_node = 1 This is the choice we mad to connect. But be careful... this value is not the best way to select a node. We will see a better method in the next chapter. result = DxOMSPlugOutNode(select_out_node) This method is called to create a link between the external Node and your program interface. At this time, you are really connected and you can send events in the OUTput port. Next, do the same thing with the INPUT nodes ports ' get the nodes IN list NOTE : This time, DxOMSGetNodes uses 1 to select INput nodes.
Midi disconnection This time, we just have to close the connection if it is active. Just test this value and close the client session is it is TRUE. if oms_connected = true then You don't have to set anymore oms_connected after DxOMSdisconnect() but just do it for clearity of the program. Next step : test the program, with OMS, play the notes in the "win" window Open the "Win" window edit window "Win" is opened just after the Midi connection. To prevent any problem, this window only appears if your program successfully connects to OMS studio. If you don't do that, you really create problems in your program ! The Win window contains 2 buttons. With the second one, you quit the app... ok ! But the first let you play notes on the channel 1, and to the first node of the list... With DxDurNote, you tell the output to send synchronously note events to the OUT port of your program, and with the specific duration (1/60th of a second) by value. parameters : 1 = channel one
NOW, RUN the program and test your button.... You ear music ? No ? verify your synth, the midi junction, test again your studio in OMS setup app No more ? change the note channel, change the node number (within the node count). No more music ?... hum! do you ear your cat in the kitchen... it's very hungry no, Mr Beethoven ???!!
1/ Create a combo box in the Win Window to let the user selecting an output node
In the chapter 3, (c)1999 - RealVision software
|