Csound Csound-dev Csound-tekno Search About

[Csnd] MIDI input after recompiling an instance of Csound...

Date2013-03-25 11:06
FromRory Walsh
Subject[Csnd] MIDI input after recompiling an instance of Csound...
When I create my Csound object I call the following functions to set up midi IO:

csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
csound->SetExternalMidiReadCallback(ReadMidiData);
csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
csound->SetExternalMidiWriteCallback(WriteMidiData);

In order to recompile my instance I first call csoundReset() which I
assume unregisters the above callbacks and frees up any memory? The
problem is I get a segfault at the following csound method if I try to
re-register them after the recompile.

/* Set real time MIDI function pointers. */
PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *csound, int
(*func)(CSOUND *, void **, const char *))
{
    csound->midiGlobals->MidiInOpenCallback = func;
}

Here's the steps I take in recompiling:

csound->DeleteChannelList(csoundChanList);
csound->Reset();

//csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
//csound->SetExternalMidiReadCallback(ReadMidiData);
//csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
//csound->SetExternalMidiWriteCallback(WriteMidiData);

CSspout = nullptr;
CSspin = nullptr;
csCompileResult =
csound->Compile(const_cast(csdFile.getFullPathName().toUTF8().getAddress()));

Any ideas? This has never been an issue in the past as I've always
deleted my instance of Csound and re-instantiated it, but I'd rather
just re-compiling as it seems much quicker.

Date2013-03-25 12:01
Fromandy fillebrown
SubjectRe: [Csnd] MIDI input after recompiling an instance of Csound...
On Mon, Mar 25, 2013 at 7:06 AM, Rory Walsh  wrote:
> When I create my Csound object I call the following functions to set up midi IO:
>
> csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
> csound->SetExternalMidiReadCallback(ReadMidiData);
> csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
> csound->SetExternalMidiWriteCallback(WriteMidiData);
>
> In order to recompile my instance I first call csoundReset() which I
> assume unregisters the above callbacks and frees up any memory?

That assumption may be incorrect.

PUBLIC void csoundReset(CSOUND *csound)
{
    ...
    csound->csoundCallbacks_ = saved_env->csoundCallbacks_;
    ...
}



> The problem is I get a segfault at the following csound method if I try to
> re-register them after the recompile.
>
> /* Set real time MIDI function pointers. */
> PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *csound, int
> (*func)(CSOUND *, void **, const char *))
> {
>     csound->midiGlobals->MidiInOpenCallback = func;
> }
>
> Here's the steps I take in recompiling:
>
> csound->DeleteChannelList(csoundChanList);
> csound->Reset();
>
> //csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
> //csound->SetExternalMidiReadCallback(ReadMidiData);
> //csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
> //csound->SetExternalMidiWriteCallback(WriteMidiData);
>
> CSspout = nullptr;
> CSspin = nullptr;
> csCompileResult =
> csound->Compile(const_cast(csdFile.getFullPathName().toUTF8().getAddress()));
>
> Any ideas? This has never been an issue in the past as I've always
> deleted my instance of Csound and re-instantiated it, but I'd rather
> just re-compiling as it seems much quicker.

It is significantly quicker.  Try not resetting the callbacks after
calling csoundReset.  They may still work.

Cheers,
~ andy.f

Date2013-03-25 12:02
Fromandy fillebrown
SubjectRe: [Csnd] MIDI input after recompiling an instance of Csound...
bah, cross post.  disregard.

~ af



On Mon, Mar 25, 2013 at 8:01 AM, andy fillebrown
 wrote:
> On Mon, Mar 25, 2013 at 7:06 AM, Rory Walsh  wrote:
>> When I create my Csound object I call the following functions to set up midi IO:
>>
>> csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
>> csound->SetExternalMidiReadCallback(ReadMidiData);
>> csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
>> csound->SetExternalMidiWriteCallback(WriteMidiData);
>>
>> In order to recompile my instance I first call csoundReset() which I
>> assume unregisters the above callbacks and frees up any memory?
>
> That assumption may be incorrect.
>
> PUBLIC void csoundReset(CSOUND *csound)
> {
>     ...
>     csound->csoundCallbacks_ = saved_env->csoundCallbacks_;
>     ...
> }
>
>
>
>> The problem is I get a segfault at the following csound method if I try to
>> re-register them after the recompile.
>>
>> /* Set real time MIDI function pointers. */
>> PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *csound, int
>> (*func)(CSOUND *, void **, const char *))
>> {
>>     csound->midiGlobals->MidiInOpenCallback = func;
>> }
>>
>> Here's the steps I take in recompiling:
>>
>> csound->DeleteChannelList(csoundChanList);
>> csound->Reset();
>>
>> //csound->SetExternalMidiInOpenCallback(OpenMidiInputDevice);
>> //csound->SetExternalMidiReadCallback(ReadMidiData);
>> //csound->SetExternalMidiOutOpenCallback(OpenMidiOutputDevice);
>> //csound->SetExternalMidiWriteCallback(WriteMidiData);
>>
>> CSspout = nullptr;
>> CSspin = nullptr;
>> csCompileResult =
>> csound->Compile(const_cast(csdFile.getFullPathName().toUTF8().getAddress()));
>>
>> Any ideas? This has never been an issue in the past as I've always
>> deleted my instance of Csound and re-instantiated it, but I'd rather
>> just re-compiling as it seems much quicker.
>
> It is significantly quicker.  Try not resetting the callbacks after
> calling csoundReset.  They may still work.
>
> Cheers,
> ~ andy.f