// set a node's control value - name argument void Node_SetControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, float inValue) { if (inNode->mIsGroup) { Group_SetControl((Group*)inNode, inHash, inName, inIndex, inValue); } else { Graph_SetControl((Graph*)inNode, inHash, inName, inIndex, inValue); } }
void Graph_SetControl(Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float inValue) { ParamSpecTable* table = GRAPH_PARAM_TABLE(inGraph); ParamSpec *spec = table->Get(inHash, inName); if (!spec || inIndex >= spec->mNumChannels) return; //printf("setting: %s: to value %f\n", spec->mName, inValue); Graph_SetControl(inGraph, spec->mIndex + inIndex, inValue); }
void Graph_Ctor(World *inWorld, GraphDef *inGraphDef, Graph *graph, sc_msg_iter *msg,bool argtype)//true for normal args , false for setn type args { //scprintf("->Graph_Ctor\n"); // hit the memory allocator only once. char *memory = (char*)graph + sizeof(Graph); // allocate space for children uint32 numUnits = inGraphDef->mNumUnitSpecs; graph->mNumUnits = numUnits; inWorld->mNumUnits += numUnits; inWorld->mNumGraphs ++; graph->mUnits = (Unit**)memory; memory += inGraphDef->mUnitsAllocSize; // set calc func graph->mNode.mCalcFunc = (NodeCalcFunc)&Graph_FirstCalc; // allocate wires graph->mNumWires = inGraphDef->mNumWires; graph->mWire = (Wire*)memory; memory += inGraphDef->mWiresAllocSize; graph->mNumCalcUnits = inGraphDef->mNumCalcUnits; graph->mCalcUnits = (Unit**)memory; memory += inGraphDef->mCalcUnitsAllocSize; // initialize controls uint32 numControls = inGraphDef->mNumControls; graph->mNumControls = numControls; graph->mControls = (float*)memory; memory += inGraphDef->mControlAllocSize; graph->mMapControls = (float**)memory; memory += inGraphDef->mMapControlsAllocSize; graph->mControlRates = (int*)memory; memory += inGraphDef->mMapControlRatesAllocSize; { float* graphControls = graph->mControls; float* initialControlValues = inGraphDef->mInitialControlValues; float** graphMapControls = graph->mMapControls; /* add */ int* graphControlRates = graph->mControlRates; for (uint32 i=0; i<numControls; ++i, ++graphControls) { *graphControls = initialControlValues[i]; graphMapControls[i] = graphControls; /* add */ graphControlRates[i] = 0; // init to 0 for now... control bus is 1, audio is 2 } } // set controls //if argtype == true -> normal args as always //if argtype == false -> setn type args if(argtype) { while( msg->remain()>=8) { int i = 0; int loop = 0; if (msg->nextTag('i') == 's') { int32* name = msg->gets4(); int32 hash = Hash(name); do { switch (msg->nextTag('f') ) { case 'f' : case 'i' : { float32 value = msg->getf(); Graph_SetControl(graph, hash, name, i, value); break; } case 's' : { const char* string = msg->gets(); if ( *string == 'c') { int bus = sc_atoi(string+1); Graph_MapControl(graph, hash, name, i, bus); } else { if (*string == 'a') { int bus = sc_atoi(string+1); Graph_MapAudioControl(graph, hash, name, i, bus); } } break; } case ']': msg->count++; loop -= 1; break; case '[': msg->count++; loop += 1; i -= 1; break; } ++i; } while (loop); } else { int32 index = msg->geti(); do { switch (msg->nextTag('f') ) { case 'f' : case 'i' : { float32 value = msg->getf(); Graph_SetControl(graph, index + i, value); break; } case 's' : { const char* string = msg->gets(); if ( *string == 'c') { int bus = sc_atoi(string+1); Graph_MapControl(graph, index + i, bus); } else { if (*string == 'a') { int bus = sc_atoi(string+1); Graph_MapAudioControl(graph, index + i, bus); } } break; } case ']': msg->count++; loop -= 1; break; case '[': msg->count++; loop += 1; i -= 1; break; } ++i; } while (loop); } } } //{ // while( msg->remain()>=8) { // int i = 0; // int loop = 0; // if (msg->nextTag('i') == 's') { // int32* name = msg->gets4(); // int32 hash = Hash(name); // if (msg->nextTag('f') == '[' ) { // msg->count++; // loop = 1; // } // do { // if (msg->nextTag('f') == 's' ) { // const char* string = msg->gets(); // if ( *string == 'c') { // int bus = sc_atoi(string+1); // Graph_MapControl(graph, hash, name, i, bus); // } // } else { // if (msg->nextTag('f') == ']' ) { // msg->count++; // loop = 0; // } else { // float32 value = msg->getf(); // Graph_SetControl(graph, hash, name, i, value); // } // } // ++i; // } // while (loop); // } else { // int32 index = msg->geti(); // if (msg->nextTag('f') == '[' ) { // msg->count++; // loop = 1; // } // do { // if (msg->nextTag('f') == 's') { // const char* string = msg->gets(); // if (*string == 'c') { // int bus = sc_atoi(string+1); // Graph_MapControl(graph, index + i, bus); // } // } else { // if (msg->nextTag('f') == ']' ) { // msg->count++; // loop = 0; // } else { // float32 value = msg->getf(); // Graph_SetControl(graph, index + i, value); // } // } // ++i; // } // while (loop); // } // } // // } else{ while (msg->remain()) { if (msg->nextTag('i') == 's') { int32* name = msg->gets4(); int32 hash = Hash(name); int32 n = msg->geti(); for (int i=0; msg->remain() && i<n; ++i) { if (msg->nextTag('f') == 's') { const char* string = msg->gets(); if (*string == 'c') { int bus = sc_atoi(string+1); Graph_MapControl(graph, hash, name, i, bus); //Node_MapControl(node, hash, name, i, bus); } else { if (*string == 'a') { int bus = sc_atoi(string+1); Graph_MapAudioControl(graph, hash, name, i, bus); } } } else { float32 value = msg->getf(); Graph_SetControl(graph, hash, name, i, value); //Node_SetControl(node, hash, name, i, value); } } } else { int32 index = msg->geti(); int32 n = msg->geti(); for (int i=0; msg->remain() && i<n; ++i) { if (msg->nextTag('f') == 's') { const char* string = msg->gets(); if (*string == 'c') { int bus = sc_atoi(string+1); Graph_MapControl(graph, index+i, bus); //Node_MapControl(node, index+i, bus); } else { if (*string == 'a') { int bus = sc_atoi(string+1); Graph_MapAudioControl(graph, index + i, bus); } } } else { float32 value = msg->getf(); Graph_SetControl(graph, index+i, value); //Node_SetControl(node, index+i, value); } } } } } // set up scalar values Wire *graphWires = graph->mWire; int numConstants = inGraphDef->mNumConstants; { float *constants = inGraphDef->mConstants; Wire *wire = graphWires; for (int i=0; i<numConstants; ++i, ++wire) { wire->mFromUnit = 0; wire->mCalcRate = calc_ScalarRate; wire->mBuffer = &wire->mScalarValue; wire->mScalarValue = constants[i]; } } graph->mSampleOffset = inWorld->mSampleOffset; graph->mSubsampleOffset = inWorld->mSubsampleOffset; graph->mRGen = inWorld->mRGen; // defaults to rgen zero. graph->mLocalAudioBusUnit = NULL; graph->mLocalControlBusUnit = NULL; graph->localBufNum = 0; graph->localMaxBufNum = 0; // this is set from synth // initialize units //scprintf("initialize units\n"); Unit** calcUnits = graph->mCalcUnits; Unit** graphUnits = graph->mUnits; int calcCtr=0; float *bufspace = inWorld->hw->mWireBufSpace; uint32 wireCtr = numConstants; // never more than numConstants + numOutputs UnitSpec *unitSpec = inGraphDef->mUnitSpecs; for (uint32 i=0; i<numUnits; ++i, ++unitSpec) { // construct unit from spec Unit *unit = Unit_New(inWorld, unitSpec, memory); // set parent unit->mParent = graph; unit->mParentIndex = i; graphUnits[i] = unit; { // hook up unit inputs //scprintf("hook up unit inputs\n"); InputSpec *inputSpec = unitSpec->mInputSpec; Wire** unitInput = unit->mInput; float** unitInBuf = unit->mInBuf; uint32 numInputs = unitSpec->mNumInputs; for (uint32 j=0; j<numInputs; ++j, ++inputSpec) { Wire *wire = graphWires + inputSpec->mWireIndex; unitInput[j] = wire; unitInBuf[j] = wire->mBuffer; } } { // hook up unit outputs //scprintf("hook up unit outputs\n"); Wire** unitOutput = unit->mOutput; float** unitOutBuf = unit->mOutBuf; uint32 numOutputs = unitSpec->mNumOutputs; Wire *wire = graphWires + wireCtr; wireCtr += numOutputs; int unitCalcRate = unit->mCalcRate; if (unitCalcRate == calc_FullRate) { OutputSpec *outputSpec = unitSpec->mOutputSpec; for (uint32 j=0; j<numOutputs; ++j, ++wire, ++outputSpec) { wire->mFromUnit = unit; wire->mCalcRate = calc_FullRate; wire->mBuffer = bufspace + outputSpec->mBufferIndex; unitOutput[j] = wire; unitOutBuf[j] = wire->mBuffer; } calcUnits[calcCtr++] = unit; } else { for (uint32 j=0; j<numOutputs; ++j, ++wire) { wire->mFromUnit = unit; wire->mCalcRate = unitCalcRate; wire->mBuffer = &wire->mScalarValue; unitOutput[j] = wire; unitOutBuf[j] = wire->mBuffer; } if (unitCalcRate == calc_BufRate) { calcUnits[calcCtr++] = unit; } } } } inGraphDef->mRefCount ++ ; }
void Graph_SetControl(Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float inValue) { ParamSpecTable* table = GRAPH_PARAM_TABLE(inGraph); ParamSpec *spec = table->Get(inHash, inName); if (spec) Graph_SetControl(inGraph, spec->mIndex + inIndex, inValue); }