Csound Csound-dev Csound-tekno Search About

[Cs-dev] csoundGetChannelPtr()...

Date2008-03-21 15:00
From"Rory Walsh"
Subject[Cs-dev] csoundGetChannelPtr()...
As I understand it if I call csoundGetChannelPtr with type set to 0 it
will check that the channel exists but not create one if it doesn't exist.
If so the following code(see below) should not print "a channel named amp
exists.." when run given that I don't set up a channel called "amp" in my
csd file. Unfortunately it does print this message. Can anyone see why
this is? I really need to be able to check for channels without creating
them if they don't exist, anyone ideas?

Rory.

#include "csound.hpp"
#include "csPerfThread.hpp"
#include 
using namespace std;

int main(int argc, char *argv[])
{
int hold=1;
MYFLT* val;
/*create a Csound object*/
Csound* csound = new Csound;
/*pre-compile instance of csound*/
csound->PreCompile();
/*compile instance of csound*/
csound->Compile("test.csd");
/* create a CsoundPerfThread object */
CsoundPerformanceThread* perf =
new CsoundPerformanceThread(csound->GetCsound());
/* start csound thread */
perf->Play();

while(hold){
    if (csoundGetChannelPtr(csound->GetCsound(),
			    &val,
			  	"amp",
			    0)==CSOUND_CONTROL_CHANNEL|CSOUND_OUTPUT_CHANNEL){
	      cout << "a channel named amp exists..";
      }
cin >> hold;
csound->SetChannel("freq", (MYFLT)hold);
}

/* stop thread */
perf->Stop();
/*delete instance of csound*/
delete csound;
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2008-03-21 15:57
FromDavis Pyon
SubjectRe: [Cs-dev] csoundGetChannelPtr()...
You could try using csoundListChannels().  For example:

CsoundChannelListEntry *csoundChanList = NULL;
int numCsoundChannels;
int type = CSOUND_OUTPUT_CHANNEL | CSOUND_CONTROL_CHANNEL;

numCsoundChannels = csoundListChannels(csound->GetCsound(), &csoundChanList);

for(i=0; icsound, csoundChanList);


The only caveat being that you'll have to either declare your channels
with chn_i/chn_k or start the Csound performance so that any channels in
your code are created before you call csoundListChannels().

Happy CsoundAPI'ing,

Davis

 

--- Rory Walsh  wrote:

> As I understand it if I call csoundGetChannelPtr with type set to 0 it
> will check that the channel exists but not create one if it doesn't exist.
> If so the following code(see below) should not print "a channel named amp
> exists.." when run given that I don't set up a channel called "amp" in my
> csd file. Unfortunately it does print this message. Can anyone see why
> this is? I really need to be able to check for channels without creating
> them if they don't exist, anyone ideas?
> 
> Rory.
> 
> #include "csound.hpp"
> #include "csPerfThread.hpp"
> #include 
> using namespace std;
> 
> int main(int argc, char *argv[])
> {
> int hold=1;
> MYFLT* val;
> /*create a Csound object*/
> Csound* csound = new Csound;
> /*pre-compile instance of csound*/
> csound->PreCompile();
> /*compile instance of csound*/
> csound->Compile("test.csd");
> /* create a CsoundPerfThread object */
> CsoundPerformanceThread* perf =
> new CsoundPerformanceThread(csound->GetCsound());
> /* start csound thread */
> perf->Play();
> 
> while(hold){
>     if (csoundGetChannelPtr(csound->GetCsound(),
> 			    &val,
> 			  	"amp",
> 			    0)==CSOUND_CONTROL_CHANNEL|CSOUND_OUTPUT_CHANNEL){
> 	      cout << "a channel named amp exists..";
>       }
> cin >> hold;
> csound->SetChannel("freq", (MYFLT)hold);
> }
> 
> /* stop thread */
> perf->Stop();
> /*delete instance of csound*/
> delete csound;
> }


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2008-03-21 19:10
From"Rory Walsh"
SubjectRe: [Cs-dev] csoundGetChannelPtr()...
Thank you David, that code should go into the Csound API hall of fame!
You've really saved me a lot a time, thanks again,

Rory.


> You could try using csoundListChannels().  For example:
>
> CsoundChannelListEntry *csoundChanList = NULL;
> int numCsoundChannels;
> int type = CSOUND_OUTPUT_CHANNEL | CSOUND_CONTROL_CHANNEL;
>
> numCsoundChannels = csoundListChannels(csound->GetCsound(),
> &csoundChanList);
>
> for(i=0; i {
>     if((csoundChanList[i].type & type) == type &&
>         strcmp(csoundChanList[i].name, "amp") == 0)
>     {
>         cout << "a channel named amp exists..";
>     }
> }
> if(csoundChanList) csoundDeleteChannelList(x->csound, csoundChanList);
>
>
> The only caveat being that you'll have to either declare your channels
> with chn_i/chn_k or start the Csound performance so that any channels in
> your code are created before you call csoundListChannels().
>
> Happy CsoundAPI'ing,
>
> Davis
>
>
>
> --- Rory Walsh  wrote:
>
>> As I understand it if I call csoundGetChannelPtr with type set to 0 it
>> will check that the channel exists but not create one if it doesn't
>> exist.
>> If so the following code(see below) should not print "a channel named
>> amp
>> exists.." when run given that I don't set up a channel called "amp" in
>> my
>> csd file. Unfortunately it does print this message. Can anyone see why
>> this is? I really need to be able to check for channels without creating
>> them if they don't exist, anyone ideas?
>>
>> Rory.
>>
>> #include "csound.hpp"
>> #include "csPerfThread.hpp"
>> #include 
>> using namespace std;
>>
>> int main(int argc, char *argv[])
>> {
>> int hold=1;
>> MYFLT* val;
>> /*create a Csound object*/
>> Csound* csound = new Csound;
>> /*pre-compile instance of csound*/
>> csound->PreCompile();
>> /*compile instance of csound*/
>> csound->Compile("test.csd");
>> /* create a CsoundPerfThread object */
>> CsoundPerformanceThread* perf =
>> new CsoundPerformanceThread(csound->GetCsound());
>> /* start csound thread */
>> perf->Play();
>>
>> while(hold){
>>     if (csoundGetChannelPtr(csound->GetCsound(),
>> 			    &val,
>> 			  	"amp",
>> 			    0)==CSOUND_CONTROL_CHANNEL|CSOUND_OUTPUT_CHANNEL){
>> 	      cout << "a channel named amp exists..";
>>       }
>> cin >> hold;
>> csound->SetChannel("freq", (MYFLT)hold);
>> }
>>
>> /* stop thread */
>> perf->Stop();
>> /*delete instance of csound*/
>> delete csound;
>> }
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2008-03-21 23:14
FromDavis Pyon
SubjectRe: [Cs-dev] csoundGetChannelPtr()...
--- Rory Walsh  wrote:

> Thank you David, that code should go into the Csound API hall of fame!
> You've really saved me a lot a time, thanks again,

You're welcome :) 

By the way, according to csound.h, your code should work.  From csound.h:

* Note: to find out the type of a channel without actually creating or
* changing it, set 'type' to zero, so that the return value will be either
* the type of the channel, or CSOUND_ERROR if it does not exist.

I just took a brief glance at csoundGetChannelPtr() in bus.c. 
As far as I can tell, someone just forgot to implement this feature.

Davis 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2008-03-22 16:10
From"Rory Walsh"
SubjectRe: [Cs-dev] csoundGetChannelPtr()...
> By the way, according to csound.h, your code should work.  From csound.h:

Hence the confusion. Cheers,
Rory.




-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net