GraphDef* GraphDefLib_Read(World *inWorld, char* buffer, GraphDef* inList) { int32 magic = readInt32_be(buffer); if (magic != (('S'<<24)|('C'<<16)|('g'<<8)|'f') /*'SCgf'*/) return inList; int32 version = readInt32_be(buffer); uint32 numDefs, i; switch (version) { case 2: numDefs = readInt16_be(buffer); for (i=0; i<numDefs; ++i) { inList = GraphDef_Read(inWorld, buffer, inList, version); } return inList; break; case 1: case 0: numDefs = readInt16_be(buffer); for (i=0; i<numDefs; ++i) { inList = GraphDef_ReadVer1(inWorld, buffer, inList, version); // handles 1 and 0 } return inList; break; default: return inList; break; } }
void UnitSpec_Read(UnitSpec* inUnitSpec, char*& buffer) { int32 name[kSCNameLen]; ReadName(buffer, name); inUnitSpec->mUnitDef = GetUnitDef(name); if (!inUnitSpec->mUnitDef) { char str[256]; sprintf(str, "UGen '%s' not installed.", (char*)name); throw std::runtime_error(str); return; } inUnitSpec->mCalcRate = readInt8(buffer); inUnitSpec->mNumInputs = readInt32_be(buffer); inUnitSpec->mNumOutputs = readInt32_be(buffer); inUnitSpec->mSpecialIndex = readInt16_be(buffer); inUnitSpec->mInputSpec = (InputSpec*)malloc(sizeof(InputSpec) * inUnitSpec->mNumInputs); inUnitSpec->mOutputSpec = (OutputSpec*)malloc(sizeof(OutputSpec) * inUnitSpec->mNumOutputs); for (uint32 i=0; i<inUnitSpec->mNumInputs; ++i) { InputSpec_Read(inUnitSpec->mInputSpec + i, buffer); } for (uint32 i=0; i<inUnitSpec->mNumOutputs; ++i) { OutputSpec_Read(inUnitSpec->mOutputSpec + i, buffer); } uint64 numPorts = inUnitSpec->mNumInputs + inUnitSpec->mNumOutputs; inUnitSpec->mAllocSize = inUnitSpec->mUnitDef->mAllocSize + numPorts * (sizeof(Wire*) + sizeof(float*)); }
void InputSpec_Read(InputSpec* inInputSpec, char*& buffer) { inInputSpec->mFromUnitIndex = readInt32_be(buffer); inInputSpec->mFromOutputIndex = readInt32_be(buffer); inInputSpec->mWireIndex = -1; }
void ParamSpec_Read(ParamSpec* inParamSpec, char*& buffer) { ReadName(buffer, inParamSpec->mName); inParamSpec->mIndex = readInt32_be(buffer); inParamSpec->mHash = Hash(inParamSpec->mName); }
// ver 2 GraphDef* GraphDef_Read(World *inWorld, char*& buffer, GraphDef* inList, int32 inVersion) { int32 name[kSCNodeDefNameLen]; ReadNodeDefName(buffer, name); GraphDef* graphDef = (GraphDef*)calloc(1, sizeof(GraphDef)); graphDef->mOriginal = graphDef; graphDef->mNodeDef.mAllocSize = sizeof(Graph); memcpy((char*)graphDef->mNodeDef.mName, (char*)name, kSCNodeDefNameByteLen); graphDef->mNodeDef.mHash = Hash(graphDef->mNodeDef.mName); graphDef->mNumConstants = readInt32_be(buffer); graphDef->mConstants = (float*)malloc(graphDef->mNumConstants * sizeof(float)); for (uint32 i=0; i<graphDef->mNumConstants; ++i) { graphDef->mConstants[i] = readFloat_be(buffer); } graphDef->mNumControls = readInt32_be(buffer); graphDef->mInitialControlValues = (float32*)malloc(sizeof(float32) * graphDef->mNumControls); for (uint32 i=0; i<graphDef->mNumControls; ++i) { graphDef->mInitialControlValues[i] = readFloat_be(buffer); } graphDef->mNumParamSpecs = readInt32_be(buffer); if (graphDef->mNumParamSpecs) { int hashTableSize = NEXTPOWEROFTWO(graphDef->mNumParamSpecs); graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, hashTableSize, false); graphDef->mParamSpecs = (ParamSpec*)malloc(graphDef->mNumParamSpecs * sizeof(ParamSpec)); for (uint32 i=0; i<graphDef->mNumParamSpecs; ++i) { ParamSpec *paramSpec = graphDef->mParamSpecs + i; ParamSpec_Read(paramSpec, buffer); graphDef->mParamSpecTable->Add(paramSpec); } } else { // empty table to eliminate test in Graph_SetControl graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, 4, false); graphDef->mParamSpecs = 0; } graphDef->mNumWires = graphDef->mNumConstants; graphDef->mNumUnitSpecs = readInt32_be(buffer); graphDef->mUnitSpecs = (UnitSpec*)malloc(sizeof(UnitSpec) * graphDef->mNumUnitSpecs); graphDef->mNumCalcUnits = 0; for (uint32 i=0; i<graphDef->mNumUnitSpecs; ++i) { UnitSpec *unitSpec = graphDef->mUnitSpecs + i; UnitSpec_Read(unitSpec, buffer); switch (unitSpec->mCalcRate) { case calc_ScalarRate : unitSpec->mRateInfo = &inWorld->mBufRate; break; case calc_BufRate : graphDef->mNumCalcUnits++; unitSpec->mRateInfo = &inWorld->mBufRate; break; case calc_FullRate : graphDef->mNumCalcUnits++; unitSpec->mRateInfo = &inWorld->mFullRate; break; case calc_DemandRate : unitSpec->mRateInfo = &inWorld->mBufRate; break; } graphDef->mNodeDef.mAllocSize += unitSpec->mAllocSize; graphDef->mNumWires += unitSpec->mNumOutputs; } DoBufferColoring(inWorld, graphDef); graphDef->mWiresAllocSize = graphDef->mNumWires * sizeof(Wire); graphDef->mUnitsAllocSize = graphDef->mNumUnitSpecs * sizeof(Unit*); graphDef->mCalcUnitsAllocSize = graphDef->mNumCalcUnits * sizeof(Unit*); graphDef->mNodeDef.mAllocSize += graphDef->mWiresAllocSize; graphDef->mNodeDef.mAllocSize += graphDef->mUnitsAllocSize; graphDef->mNodeDef.mAllocSize += graphDef->mCalcUnitsAllocSize; graphDef->mControlAllocSize = graphDef->mNumControls * sizeof(float); graphDef->mNodeDef.mAllocSize += graphDef->mControlAllocSize; graphDef->mMapControlsAllocSize = graphDef->mNumControls * sizeof(float*); graphDef->mNodeDef.mAllocSize += graphDef->mMapControlsAllocSize; graphDef->mMapControlRatesAllocSize = graphDef->mNumControls * sizeof(int*); graphDef->mNodeDef.mAllocSize += graphDef->mMapControlRatesAllocSize; graphDef->mNext = inList; graphDef->mRefCount = 1; graphDef->mNumVariants = readInt16_be(buffer); if (graphDef->mNumVariants) { graphDef->mVariants = (GraphDef*)calloc(graphDef->mNumVariants, sizeof(GraphDef)); for (uint32 i=0; i<graphDef->mNumVariants; ++i) { GraphDef_ReadVariant(inWorld, buffer, graphDef, graphDef->mVariants + i); } } return graphDef; }
/** \note Relevant supernova code: \c sc_synthdef::prepare() * \note Relevant v1 code: \c GraphDef_ReadVer1() */ GraphDef* GraphDef_Read(World *inWorld, char*& buffer, GraphDef* inList, int32 inVersion) { int32 name[kSCNodeDefNameLen]; ReadNodeDefName(buffer, name); GraphDef* graphDef = (GraphDef*)calloc(1, sizeof(GraphDef)); graphDef->mOriginal = graphDef; graphDef->mNodeDef.mAllocSize = sizeof(Graph); memcpy((char*)graphDef->mNodeDef.mName, (char*)name, kSCNodeDefNameByteLen); graphDef->mNodeDef.mHash = Hash(graphDef->mNodeDef.mName); graphDef->mNumConstants = readInt32_be(buffer); graphDef->mConstants = (float*)malloc(graphDef->mNumConstants * sizeof(float)); for (uint32 i=0; i<graphDef->mNumConstants; ++i) { graphDef->mConstants[i] = readFloat_be(buffer); } graphDef->mNumControls = readInt32_be(buffer); graphDef->mInitialControlValues = (float32*)malloc(sizeof(float32) * graphDef->mNumControls); for (uint32 i=0; i<graphDef->mNumControls; ++i) { graphDef->mInitialControlValues[i] = readFloat_be(buffer); } graphDef->mNumParamSpecs = readInt32_be(buffer); calcParamSpecs(graphDef, buffer); graphDef->mNumWires = graphDef->mNumConstants; graphDef->mNumUnitSpecs = readInt32_be(buffer); graphDef->mUnitSpecs = (UnitSpec*)malloc(sizeof(UnitSpec) * graphDef->mNumUnitSpecs); graphDef->mNumCalcUnits = 0; for (uint32 i=0; i<graphDef->mNumUnitSpecs; ++i) { UnitSpec *unitSpec = graphDef->mUnitSpecs + i; UnitSpec_Read(unitSpec, buffer); switch (unitSpec->mCalcRate) { case calc_ScalarRate : unitSpec->mRateInfo = &inWorld->mBufRate; break; case calc_BufRate : graphDef->mNumCalcUnits++; unitSpec->mRateInfo = &inWorld->mBufRate; break; case calc_FullRate : graphDef->mNumCalcUnits++; unitSpec->mRateInfo = &inWorld->mFullRate; break; case calc_DemandRate : unitSpec->mRateInfo = &inWorld->mBufRate; break; } graphDef->mNodeDef.mAllocSize += unitSpec->mAllocSize; graphDef->mNumWires += unitSpec->mNumOutputs; } DoBufferColoring(inWorld, graphDef); GraphDef_SetAllocSizes(graphDef); graphDef->mNext = inList; graphDef->mRefCount = 1; graphDef->mNumVariants = readInt16_be(buffer); if (graphDef->mNumVariants) { graphDef->mVariants = (GraphDef*)calloc(graphDef->mNumVariants, sizeof(GraphDef)); for (uint32 i=0; i<graphDef->mNumVariants; ++i) { GraphDef_ReadVariant(inWorld, buffer, graphDef, graphDef->mVariants + i); } } return graphDef; }