CsoundReset() and MIDI

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

CsoundReset() and MIDI

Victor Lazzarini
Is it possible that csoundReset() is not
closing the MIDI (and perhaps the rt audio)
module?

David Akbari's problems with tclcsound (cstclsh),
seem to indicate that something is no quite
right there. He says that a second compilation
(after csStop, which calls csoundReset()) fails
because MIDI cannot be initialised (and the
audio interface seems also to still be open).

Of course, I could implement csStop with a full
clean-up using csoundDestroy() and then
csoundCreate(), but I suppose that it is not
how the API should be used, is it? From the
description of csoundReset(), we should supposedly
be able to run any number of compilations on the
same instance of CSOUND, by calling it.

I cannot test MIDI at the moment, because I am out
of the office and with no external hardware. But
perhaps Istvan can have a look at the csound library
code and re-assure me that all is correct on that
side, so I can look for other reasons for this
problem.

Victor


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

David Akbari

On Nov 1, 2005, at 8:59 AM, Victor Lazzarini wrote:

> David Akbari's problems with tclcsound (cstclsh),
> seem to indicate that something is no quite
> right there. He says that a second compilation
> (after csStop, which calls csoundReset()) fails
> because MIDI cannot be initialised (and the
> audio interface seems also to still be open).

It may also be worth noting that simply exiting and restarting the TCL
interpreter fixes it! That's been my interim solution :)


-David



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Istvan Varga
In reply to this post by Victor Lazzarini
Victor Lazzarini wrote:

> Of course, I could implement csStop with a full
> clean-up using csoundDestroy() and then
> csoundCreate(), but I suppose that it is not
> how the API should be used, is it? From the
> description of csoundReset(), we should supposedly
> be able to run any number of compilations on the
> same instance of CSOUND, by calling it.

csoundCleanup() should close the devices, and csoundReset() also
unloads the plugin libraries and in the case of PortMidi,
Pm_Terminate() is called as well. csoundDestroy() basically only
differs from reset in that it also deallocates the CSOUND structure.
It may be possible that PortMidi cannot be initialized more than
once on the Mac, in which case we probably need to write a native
driver (there are already MIDI drivers for ALSA and Windows MME).


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Victor Lazzarini
In reply to this post by Victor Lazzarini
So why is it that we can run several csound processes
in succession, and portMIDI gets initialised correctly
in each one of them? I can't see the difference between
this and terminating a csound instance with csoundDestroy()
and starting another. I have not tested doing this, but
I will surely do.

Victor

> csoundCleanup() should close the devices, and
> csoundReset() also unloads the plugin libraries and in the
> case of PortMidi, Pm_Terminate() is called as well.
> csoundDestroy() basically only differs from reset in that
> it also deallocates the CSOUND structure. It may be
> possible that PortMidi cannot be initialized more than
> once on the Mac, in which case we probably need to write a
> native driver (there are already MIDI drivers for ALSA and
> Windows MME).
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through
> End of 2005 Visit
> http://www.jboss.com/services/certification for more
> information
> _______________________________________________
> Csound-devel mailing list
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Istvan Varga
Victor Lazzarini wrote:

> So why is it that we can run several csound processes
> in succession, and portMIDI gets initialised correctly
> in each one of them? I can't see the difference between
> this and terminating a csound instance with csoundDestroy()
> and starting another. I have not tested doing this, but
> I will surely do.

If you run multiple performances in succession by starting a new
process from the command line each time, then the memory state of
the process is not preserved and everything is cleanly reloaded
by the operating system. By contrast, reusing the same process by
calling the compile/perform/reset cycle repeatedly requires
PortMidi to be reentrant and allowing for multiple calls to
Pm_Initialize() in the same address space without problems.
It is possible that PortMidi cannot be re-initialized on MacOS X
(not having access to that platform, I cannot test this), but
I have just tested restarting a MIDI performance several times
from the Python interpreter on Linux, and it worked fine.


-------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Istvan Varga
Istvan Varga wrote:

> If you run multiple performances in succession by starting a new
> process from the command line each time, then the memory state of
> the process is not preserved and everything is cleanly reloaded
> by the operating system. By contrast, reusing the same process by
> calling the compile/perform/reset cycle repeatedly requires
> PortMidi to be reentrant and allowing for multiple calls to
> Pm_Initialize() in the same address space without problems.
> It is possible that PortMidi cannot be re-initialized on MacOS X
> (not having access to that platform, I cannot test this), but
> I have just tested restarting a MIDI performance several times
> from the Python interpreter on Linux, and it worked fine.

Doing another test, it seems that while PortMidi can indeed be
restarted without problems on Linux, using multiple instances at
the same time does fail in a fatal way. On the other hand, using
the native ALSA driver with -+rtmidi=alsa is OK, even if MIDI is
used in multiple instances of Csound in the same process at the
same time.


-------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

schwaahed
On 11/1/05, Istvan Varga <[hidden email]> wrote:

> Istvan Varga wrote:
>
> > If you run multiple performances in succession by starting a new
> > process from the command line each time, then the memory state of
> > the process is not preserved and everything is cleanly reloaded
> > by the operating system. By contrast, reusing the same process by
> > calling the compile/perform/reset cycle repeatedly requires
> > PortMidi to be reentrant and allowing for multiple calls to
> > Pm_Initialize() in the same address space without problems.
> > It is possible that PortMidi cannot be re-initialized on MacOS X
> > (not having access to that platform, I cannot test this), but
> > I have just tested restarting a MIDI performance several times
> > from the Python interpreter on Linux, and it worked fine.
>
> Doing another test, it seems that while PortMidi can indeed be
> restarted without problems on Linux, using multiple instances at
> the same time does fail in a fatal way. On the other hand, using
> the native ALSA driver with -+rtmidi=alsa is OK, even if MIDI is
> used in multiple instances of Csound in the same process at the
> same time.
>
>

Could you post an example of this session?

I'm just curious.

- schwaahed


-------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Istvan Varga
schwaahed wrote:

> Could you post an example of this session?
>
> I'm just curious.

Two simple test files are attached. miditest1.py tests re-opening the
MIDI device multiple times, while miditest2.py also reads MIDI input
in two separate Csound instances at once. Edit the various settings at
the top of the files as needed.

#!/usr/bin/python

import os
import csnd

csnd.csoundSetGlobalEnv('OPCODEDIR64', '/usr/local/lib/Csound/plugins64')
csOpts = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=PortMidi -M 1'
# csOpts = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=alsa -M hw:1,0'

f = open('__miditest_tmp.csd', 'w')
print >> f, '''
<CsoundSynthesizer>
<CsOptions>
%s
</CsOptions>
<CsInstruments>
sr      =  48000
ksmps   =  32
nchnls  =  1
0dbfs   =  1

        instr 1
kcps    cpsmidib
ivel    veloc
a1      vco2 ivel * ivel * 0.00003, kcps
        out a1
        endin

</CsInstruments>
<CsScore>
i 1 0 20
e
</CsScore>
</CsoundSynthesizer>
''' % csOpts
f.close()

cs = csnd.Csound()
cs.Perform('__miditest_tmp.csd')
cs.Perform('__miditest_tmp.csd')
cs.Perform('__miditest_tmp.csd')
cs.Reset()

os.remove('__miditest_tmp.csd')


#!/usr/bin/python

import os
import csnd

csnd.csoundSetGlobalEnv('OPCODEDIR64', '/usr/local/lib/Csound/plugins64')
# csOpts1 = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=PortMidi -M 1'
# csOpts2 = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=PortMidi -M 2'
csOpts1 = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=alsa -M hw:1,0'
csOpts2 = '-d -+rtaudio=alsa -o dac:hw:0,0 -+rtmidi=alsa -M hw:1,1'

f = open('__miditest_tmp_1.csd', 'w')
print >> f, '''
<CsoundSynthesizer>
<CsOptions>
%s
</CsOptions>
<CsInstruments>
sr      =  48000
ksmps   =  32
nchnls  =  2
0dbfs   =  1

        instr 1
kcps    cpsmidib
ivel    veloc
a1      vco2 ivel * ivel * 0.00003, kcps
a2      init 0
        outs a1, a2
        endin

</CsInstruments>
<CsScore>
i 1 0 20
e
</CsScore>
</CsoundSynthesizer>
''' % csOpts1
f.close()

f = open('__miditest_tmp_2.csd', 'w')
print >> f, '''
<CsoundSynthesizer>
<CsOptions>
%s
</CsOptions>
<CsInstruments>
sr      =  48000
ksmps   =  32
nchnls  =  2
0dbfs   =  1

        instr 1
kcps    cpsmidib
ivel    veloc
a1      vco2 ivel * ivel * 0.00003, kcps, 10
a2      init 0
        outs a2, a1
        endin

</CsInstruments>
<CsScore>
i 1 0 20
e
</CsScore>
</CsoundSynthesizer>
''' % csOpts2
f.close()

cs1 = csnd.Csound()
cs2 = csnd.Csound()
cs1.Compile('__miditest_tmp_1.csd')
cs2.Compile('__miditest_tmp_2.csd')
while cs1.PerformBuffer() == 0 and cs2.PerformBuffer() == 0:
    pass
cs1.Compile('__miditest_tmp_1.csd')
cs2.Compile('__miditest_tmp_2.csd')
while cs1.PerformBuffer() == 0 and cs2.PerformBuffer() == 0:
    pass
cs1.Compile('__miditest_tmp_1.csd')
cs2.Compile('__miditest_tmp_2.csd')
while cs1.PerformBuffer() == 0 and cs2.PerformBuffer() == 0:
    pass
cs1.Reset()
cs2.Reset()

os.remove('__miditest_tmp_1.csd')
os.remove('__miditest_tmp_2.csd')

Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Victor Lazzarini
In reply to this post by Victor Lazzarini
So do you reckon PortMIDI is creating some global
variables etc that might linger in the process even after
the library module it sits in gets unloaded?

Victor


> If you run multiple performances in succession by starting
> a new process from the command line each time, then the
> memory state of the process is not preserved and
> everything is cleanly reloaded by the operating system. By
> contrast, reusing the same process by calling the
> compile/perform/reset cycle repeatedly requires PortMidi
> to be reentrant and allowing for multiple calls to
> Pm_Initialize() in the same address space without
> problems.


-------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel
Reply | Threaded
Open this post in threaded view
|

Re: CsoundReset() and MIDI

Istvan Varga
Victor Lazzarini wrote:

> So do you reckon PortMIDI is creating some global
> variables etc that might linger in the process even after
> the library module it sits in gets unloaded?

There can be many reasons of this problem. It is possible that
the libraries do not actually get unloaded on OS X, or the error
is related to how PortMidi uses the API of the system. As I do
not have access to a Mac, nor am I familiar with that platform,
I can only guess.


-------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel