示例#1
0
QString PyQcsObject::getCsStringChannel(QString channel, int index)
{
	CsoundEngine *e = m_qcs->getEngine(index);

	if (e != NULL) {
		CSOUND *cs = e->getCsound();

		if (cs != NULL) {
#ifdef CSOUND6
			int maxlen = csoundGetChannelDatasize(cs, channel.toLocal8Bit());
#else
			int maxlen = csoundGetStrVarMaxLen(cs);
#endif
			char *value = new char[maxlen];
			if ( !( csoundGetChannelPtr(cs,(MYFLT **) &value,channel.toLocal8Bit(),
										CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL))) {
				return QString(value);
			}
		}
	}
	QString message="Could not read from channel "+channel;
	PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
	mainContext.evalScript("print \'"+message+"\'");
	return QString();//m_qcs->getCsChannel(channel, index);

}
示例#2
0
void PyQcsObject::setCsChannel(QString channel, double value, int index)
{
	CsoundEngine *e = m_qcs->getEngine(index);
	MYFLT *p;
	if (e != NULL) {
		CSOUND *cs = e->getCsound();
#ifndef CSOUND6
        if (cs != NULL && !(csoundGetChannelPtr(cs, &p, channel.toLocal8Bit(), CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL))) {
            *p = (MYFLT) value;
            return;
        }
#else
        if (cs) {
            controlChannelHints_t hints;  // this does not work with csound5
			int ret = csoundGetControlChannelHints(cs, channel.toLocal8Bit(), &hints);
			if (ret == 0) {
				csoundSetControlChannel(cs, channel.toLocal8Bit(), (MYFLT) value);
				return;
			}
		}
#endif
    }

	QString message="Channel '" + channel + "' does not exist or is not exposed with chn_k.";
	PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
	mainContext.evalScript("print \'"+message+"\'");
}
示例#3
0
void PyQcsObject::setCsChannel(QString channel, QString stringValue, int index)
{
	CsoundEngine *e = m_qcs->getEngine(index);
	MYFLT *p;
	if (e != NULL) {
		CSOUND *cs = e->getCsound();
		if (cs != NULL && !(csoundGetChannelPtr(cs, &p, channel.toLocal8Bit().constData(), CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL))) {
			// FIXME not thread safe and not checking string bounds.
			strcpy((char*) p,stringValue.toLocal8Bit().constData() );
			return;
		}
	}
	QString message="Could not set string into channel "+ channel;
	PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
	mainContext.evalScript("print \'"+message+"\'");
}
 /** pass a setChannel command through to csound. only works if perf. thread is running */
 void setChannel(const char * name, MYFLT vol)
 {
     if (!csound) {
         ll->printf(1, "skipping %s, csound==NULL\n", __FUNCTION__);
         return;
     }
     if (!ThreadID)
     {
         if (_debug && (VERBOSE > 1)) fprintf(_debug, "skipping %s, ThreadID==NULL\n", __FUNCTION__);
         return ;
     }
     MYFLT *p;
     if (!(csoundGetChannelPtr(csound, &p, name, CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL)))
         *p = (MYFLT) vol;
     else
     {
         if (_debug && (VERBOSE >0)) fprintf(_debug, "ERROR: failed to set channel: %s\n", name);
     }
 }
示例#5
0
double PyQcsObject::getCsChannel(QString channel, int index)
{
	CsoundEngine *e = m_qcs->getEngine(index);
	MYFLT *value =  new MYFLT;
	//*value = 0;
	if (e != NULL) {
		CSOUND *cs = e->getCsound();
		if (cs != NULL ) {
			if ( !( csoundGetChannelPtr(cs,&value,channel.toLocal8Bit(),
										CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL)))
				return (double) *value;
		}
	}

	QString message="Could not read from channel "+channel;
	PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
	mainContext.evalScript("print \'"+message+"\'");
	return 0;//m_qcs->getCsChannel(channel, index);
}