Csound Csound-dev Csound-tekno Search About

[Cs-dev] PortMIDI cleanup

Date2005-11-02 19:20
FromVictor Lazzarini
Subject[Cs-dev] PortMIDI cleanup
I spotted something that might perhaps be
wrong on pmidi.c. It is actually to do with
porttime; porttime is started with Pt_Start(),
but never stopped with Pt_Stop(). Adding a call
to it to the module destructor allows the portmidi module
to re-start without an error in porttime. I can't
test this, because I don't have a working MIDI, but
I can see that the initialisation seems to be
happening.

Can anyone (Istvan?) add it to the CVS sources, so
that David can test it again? I also have no CVS
access at the moment.

The Portmidi code seems to have global statics everywhere,
no wonder it cannot run in more than one instance.

Perhaps a request to make it re-entrant could be passed
to its developers.

Victor


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-02 20:22
FromIstvan Varga
SubjectRe: [Cs-dev] PortMIDI cleanup
Victor Lazzarini wrote:

> I spotted something that might perhaps be
> wrong on pmidi.c. It is actually to do with
> porttime; porttime is started with Pt_Start(),
> but never stopped with Pt_Stop(). Adding a call
> to it to the module destructor allows the portmidi module
> to re-start without an error in porttime.

Yes, this may indeed be the problem. However, calling Pm_Terminate()
amd Pt_Stop() from the module destructor may not actually be a very
good idea, as it is always called regardless of whether MIDI devices
were opened or not. Perhaps I should register a reset callback after
calling Pm_Initialize() and Pt_Start() ? Even then, there are still
problems with multiple instances due to the requirement for the global
initialize/terminate calls that apparently cannot be nested in PortMidi
(not to mention any static variables in the PortMidi sources).


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-02 21:39
FromIstvan Varga
SubjectRe: [Cs-dev] PortMIDI cleanup
Victor Lazzarini wrote:

> I spotted something that might perhaps be
> wrong on pmidi.c. It is actually to do with
> porttime; porttime is started with Pt_Start(),
> but never stopped with Pt_Stop().

Well, for now, I committed this changed code:

static int stop_portmidi(CSOUND *csound, void *userData)
{
     (void) csound;
     (void) userData;
     Pm_Terminate();
     Pt_Stop();
     return 0;
}

static int start_portmidi(CSOUND *csound)
{
     if (Pm_Initialize() != pmNoError) {
       csound->ErrorMsg(csound, Str(" *** error initialising PortMIDI"));
       return -1;
     }
     if (Pt_Start(1, NULL, NULL) != ptNoError) {
       csound->ErrorMsg(csound, Str(" *** error initialising PortTime"));
       return -1;
     }
     return csound->RegisterResetCallback(csound, NULL, stop_portmidi);
}


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-02 22:13
FromMichael Worobec
Subject[Cs-dev] a CSound moment at the coffee shop ...
Hey, I had an interesting moment at the local coffee shop yesterday - I
was in line to get a coffee, with my CSound book in hand, planning to
read a chapter or two over a latte. The woman behind me spoke up: "The
CSound book!" It turns out she just finished a grad program at MIT
during which she took the CSound class. Cool coincidence. Never leave
home without your CSound book...

Mike Worobec


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-03 03:11
FromIain Duncan
SubjectRe: [Cs-dev] PortMIDI cleanup
Which platform are you on Victor? You should be able to test portmidi 
with virtual midi loopbacks of some sort. I have used PD and virmidi on 
linux before to test portmidi code of my own, and on windows I know 
there is midi-yoke/midi-ox.

Iain

Victor Lazzarini wrote:
> I spotted something that might perhaps be
> wrong on pmidi.c. It is actually to do with
> porttime; porttime is started with Pt_Start(),
> but never stopped with Pt_Stop(). Adding a call
> to it to the module destructor allows the portmidi module
> to re-start without an error in porttime. I can't
> test this, because I don't have a working MIDI, but
> I can see that the initialisation seems to be
> happening.
> 
> Can anyone (Istvan?) add it to the CVS sources, so
> that David can test it again? I also have no CVS
> access at the moment.
> 
> The Portmidi code seems to have global statics everywhere,
> no wonder it cannot run in more than one instance.
> 
> Perhaps a request to make it re-entrant could be passed
> to its developers.
> 
> Victor
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-03 13:46
FromIstvan Varga
SubjectRe: [Cs-dev] PortMIDI cleanup
Note that there are also native drivers for ALSA and Windows MME
(but not OS X yet), and these are expected to work correctly when
restarted or run in multiple instances. I did not test these
extensively (particularly the Win32 one), so feedback on how well
they work is welcome.
The use of ALSA is enabled with:

-+rtmidi=alsa -M hw:x,y

   where x and y correspond to /dev/snd/midiCxDy

for MME, use these options:

-+rtmidi=mme -M x
   or
-+rtmidi=winmm -M x

   where x is a device number (not necessarily the same as with
   PortMidi). An out of range number like -M 1000 will print the
   list of available devices.

Of course, MIDI output is also supported, just use the -Q option
(device selection syntax is the same as in the case of input).

Iain Duncan wrote:

> Which platform are you on Victor? You should be able to test portmidi 
> with virtual midi loopbacks of some sort. I have used PD and virmidi on 
> linux before to test portmidi code of my own, and on windows I know 
> there is midi-yoke/midi-ox.
> 
> Iain
> 
> Victor Lazzarini wrote:
> 
>> I spotted something that might perhaps be
>> wrong on pmidi.c. It is actually to do with
>> porttime; porttime is started with Pt_Start(),
>> but never stopped with Pt_Stop(). Adding a call
>> to it to the module destructor allows the portmidi module
>> to re-start without an error in porttime. I can't
>> test this, because I don't have a working MIDI, but
>> I can see that the initialisation seems to be
>> happening.
>>
>> Can anyone (Istvan?) add it to the CVS sources, so
>> that David can test it again? I also have no CVS
>> access at the moment.
>>
>> The Portmidi code seems to have global statics everywhere,
>> no wonder it cannot run in more than one instance.
>>
>> Perhaps a request to make it re-entrant could be passed
>> to its developers.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-11-03 16:39
FromDavid Akbari
SubjectRe: [Cs-dev] PortMIDI cleanup
On Nov 3, 2005, at 8:46 AM, Istvan Varga wrote:

> Note that there are also native drivers for ALSA and Windows MME
> (but not OS X yet), and these are expected to work correctly when
> restarted or run in multiple instances.

CoreMIDI also supports restarting and running in multiple instances; I 
would imagine this is the OS X equivalent for the native ALSA and 
Windows MME drivers.

In this situation it is a shame ma++'s MacCsound is not open source, as 
I am fairly certain that it implements a CoreMIDI virtual device driver 
and of course all of it's OS specific inter-application bussing 
features. The main disadvantage however is that you cannot explicitly 
specify *which* device on your system to use (ie. MacCsound does not 
implement an equivalent to -M), in favor of a preference pane from 
another application which is also outputting data to the 
inter-application bus. Thus, users are forced to get the 
NSApplicationServices.framework involved.

In any event, I have tested the new cstclsh shell in OS X from a fresh 
Nov 2 CVS build and it is possible to re-instantiate PortMIDI in 
multiple instances without problems. I was also able to run the 
attached example several times successively without incident.

I used the following commandline:

% csCompile -odac:1 -idevaudio:1 -d -+noninterleaved=1 
-+rtaudio=CoreAudio -M0 /Users/daveakbari/Desktop/midiTest.csd

with the following unified CSD example (just for testing):



;-odac:1 -idevaudio:1 -d -+noninterleaved=1 -+rtaudio=CoreAudio -M0



sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2

/*--- ---*/

		instr	1

kstatus, kchan, kd1, kd2	midiin

	printk2	kd1

		endin

/*--- ---*/


i1	0	1000

e





-David



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net