Jump to content
Sign in to follow this  

Is this MSDN possible?

Recommended Posts

Either I'm missing something obvious, or I'm trying to do the impossible. The midi UDF contains a function called _MidiOutOpen which is intended to retrieve a MIDI handle. I am trying to create several MIDI handles to be used for playback on different instruments, but I am not having much success. I have looked at the MSDN function MidiOutOpen, but I find it quite confusing. Perhaps my approach is entirely wrong. Maybe someone can see why I am getting errors. I have also tried altering the parameters, but it didn't work. :unsure:

Local $instrument_A = _MidiOutOpen()
Local $instrument_B = _MidiOutOpen()

MsgBox(0,"Handle A",$instrument_A)
MsgBox(0,"Handle B",$instrument_B)

;Retrieves a MIDI handle and Opens the Device
;Parameters(Optional) - Device ID, Window Callback,
; instance, flags
;Author : Eynstyne
;Library : Microsoft winmm.dll
Func _MidiOutOpen($devid = 0, $callback = 0, $instance = 0, $flags = 0)
   $ret = DllCall("winmm.dll", "long", "midiOutOpen", "handle*", 0, "int", $devid, "dword_ptr", $callback, "dword_ptr", $instance, "long", $flags)
   If @error Then Return SetError(@error,0,0)
   If $ret[0] Then Return SetError(-1,$ret[0],0)
   Return $ret[1]
EndFunc   ;==>_MidiOutOpen
Edited by czardas

Share this post

Link to post
Share on other sites

It would appear I only have one midi output device, which is the reason I can't create two MIDI handles. How to solve it is still a mystery to me. My first thought was maybe I can create a virtual instrument to fool MIDI. My second thought is there has to be a lot more to this than I understand. At least I have one instrument I can use.


Looking at this page : Processing MIDI Data from Two MIDI Sources helps to shed some light on the problem I am experiencing. If I run two scripts simultaneously, I can play two instruments at the same time using midiOutShortMsg. If I knew properly how to create a midi stream, then I may be able to solve it that way. There are several other functions, but it's a bit over my head. Examples of using midiOutShortMsg can be found in the

I don't expect anyone to spend a lot of time trying to figure this out, unless it particularly interests you. I would be happy to use a work around since I only need two instruments (synchronized). Any advise is appreciated.

Improvised Work Around

I have thought of a possible work around solution, although it's not perfect. Instruments can be changed during a stream using some syntax of my own invention. The only problem is that two instruments can not play the same note at the same time using midiOutShortMsg. If a note is a continuous sound, it will dissapear at the moment the second instrument plays this same note. While this is not good for musical recording, it may actually be useful for ear training purposes, because it avoids confusing the ear with superfluous information. After the second instrument has finished playing the note, I can reintroduce the previous continuous sound without it being too obvious to the listener (because only one note out of the whole chord was stopped). With this make-shift solution, the second instrument will be heard more clearly over the chord, so this is what I am going to attempt to do. Hopefully this will be successful and I can turn a disadvantage into an advantage.

Edited by czardas

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...