[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] MIDI questions was: [sc-users] MIDIClient.init not working



Hiho,

On 12/17/08, thelych@xxxxxxxxx <thelych@xxxxxxxxx> wrote:
> Hi Marije, and all !
>
> first concerning the OS X issue, currently prDisposeMIDIClient (in
> SC_CoreMIDI.cpp)
> does not call midiCleanUp() (it just dispose the client - leaving a
> dangling state for the port pointers and report an error even if the
> client was not inited...)
>
> i think it should call directly midiCleanUp() to leave it in a clean
> state and not report an error if the client was not inited.
> (Or may be report an error only if the func fails to dispose the
> client (wich would mean just changing the midiCleanUp
> signature ...ect...) but not if there is no MIDIClient)

That all makes sense.

> this will also fix the current problem reported in os x.

I think that one needs the line removed, as I suggested in my reply to
that issue.

> -----------------------------------------------------
>
> also currently MIDIClient.disposeClient (on OSX) does not reset its
> 'initialized' classvar, leaving it as 'true' if it was disposed.
> Wich mean if you call MIDIIn.connectAll it won't re-create and re-
> connect sc to midi.
> To re-connect correctly MIDI seems you have to (after a
> MIDIClient.disposeClient):
>
> MIDIClient.init(numIns, numOuts); // reset the MIDIClient
> MIDIIn.connect(inIndex, outIndex); // re-connect MIDIIn ...ect...
>
> Marije, is it the same behaviour for Linux ? If you do not plan to
> modify soon the midi code for Linux, we can apply the patch to fix the
> os x problem ?

I will not modify the code soon, as I believe Dan committed my patch.
I will maybe make some fixes to sending MIDIOut with the latency
issue, but not before the 28th, when I have some time for it again,
and I still have to find the bug.

On Linux, whenever you reinitialise the client, it automatically frees
the previous client before making a new one inside the primitive code.

Anyway, feel free to make any fixes to OSX specific code.

sincerely,
Marije

>
> any opinion greatly appreciated on this ?
>
> best,
> charles
>
> proposition below + patch file attached:
> -----------------------------------------------------
>
>
> Index: source/lang/LangPrimSource/SC_CoreMIDI.cpp
> ===================================================================
> --- source/lang/LangPrimSource/SC_CoreMIDI.cpp	(revision 8169)
> +++ source/lang/LangPrimSource/SC_CoreMIDI.cpp	(working copy)
> @@ -310,7 +310,7 @@
>       }
>   }
>
> -void midiCleanUp();
> +int midiCleanUp();
>
>   int initMIDI(int numIn, int numOut)
>   {
> @@ -371,22 +371,34 @@
>       return errNone;
>   }
>
> -void midiCleanUp()
> -{
> +int midiCleanUp()
> +{	
> +	/*
> +	 * do not catch errors when disposing ports
> +	 * disposing the midi client will normally dispose the ports
> attached to it
> +	 * but clean up the pointers in case
> +	 */
>       for (int i=0; i<gNumMIDIOutPorts; ++i) {
>           MIDIPortDispose(gMIDIOutPort[i]);
> +		gMIDIOutPort[i] = 0;
>       }
>   	gNumMIDIOutPorts = 0;
>   	
>       for (int i=0; i<gNumMIDIInPorts; ++i) {
>           MIDIPortDispose(gMIDIInPort[i]);
> +		gMIDIInPort[i] = 0;
>       }
>   	gNumMIDIInPorts = 0;
>   	
>       if (gMIDIClient) {
> -        MIDIClientDispose(gMIDIClient);
> +		if( MIDIClientDispose(gMIDIClient) ) {
> +			post( "Error: failed to dispose MIDIClient\n" );
> +			return errFailed;
> +		}
>   		gMIDIClient = 0;
>       }
> +	
> +	return errNone;
>   }
>
>
> @@ -594,7 +606,7 @@
>   	err = slotIntVal(b, &numIn);
>   	if (err) return errWrongType;
>   	
> -	err = slotIntVal(c, &numOut);
> +	err = slotIntVal(c, &numOut);
>   	if (err) return errWrongType;
>   	
>   	return initMIDI(numIn, numOut);
> @@ -602,15 +614,7 @@
>   int prDisposeMIDIClient(VMGlobals *g, int numArgsPushed);
>   int prDisposeMIDIClient(VMGlobals *g, int numArgsPushed)
>   {
> -    PyrSlot *a;
> -    a = g->sp - 1;
> -    OSStatus err = MIDIClientDispose(gMIDIClient);
> -    if (err) {
> -        post("error could not dispose MIDIClient \n");
> -        return errFailed;
> -    }
> -    return errNone;	
> -
> +	return midiCleanUp();
>   }
>   int prRestartMIDI(VMGlobals *g, int numArgsPushed);
>   int prRestartMIDI(VMGlobals *g, int numArgsPushed)
>
>
>
>
>

_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/