// de-initialize network void net_deinit(void) { u32 i; print_dbg("\r\n deinitializing network"); for(i=0; i<net->numOps; i++) { op_deinit(net->ops[i]); } print_dbg("\r\n finished de-initializing network"); net->opPoolOffset = 0; net->numOps = 0; net->numIns = 0; net->numOuts = 0; net->numParams = 0; // unassign all I/O nodes for(i=0; i<NET_INS_MAX; i++) { net_init_inode(i); } for(i=0; i<NET_OUTS_MAX; i++) { net_init_onode(i); } }
// destroy last operator created s16 net_pop_op(void) { const s16 opIdx = net->numOps - 1; op_t* op = net->ops[opIdx]; int i=0; int x, y; app_pause(); // bail if system op if(net_op_flag (opIdx, eOpFlagSys)) { return 1; } // de-init op_deinit(op); // store the global index of the first input x = net_op_in_idx(opIdx, 0); y = x + op->numInputs; // check if anything connects here for(i=0; i<net->numOuts; i++) { // this check works b/c we know this is last op in list if( net->outs[i].target >= x ) { if( net->outs[i].target < y) { net_disconnect(i); } else { // net->outs[i].target -= op->numInputs; net_connect(i, net->outs[i].target - op->numInputs); } } } // erase input nodes while(x < y) { net_init_inode(x++); } // store the global index of the first output x = net_op_out_idx(opIdx, 0); y = x + op->numOutputs; // erase output nodes while(x < y) { net_init_onode(x++); } net->numIns -= op->numInputs; net->numOuts -= op->numOutputs; net->opPoolOffset -= op_registry[op->type].size; net->numOps -= 1; app_resume(); return 0; }
// destroy last operator created s16 net_pop_op(void) { const s16 opIdx = net->numOps - 1; op_t* op = net->ops[opIdx]; int i, j; int x, y; int ins; int numInsSave = net->numIns; int idxOld, idxNew; app_pause(); // bail if system op if(net_op_flag (opIdx, eOpFlagSys)) { return 1; } // de-init op_deinit(op); ins = op->numInputs; // store the global index of the first input x = net_op_in_idx(opIdx, 0); y = x + ins; // check if anything connects here for(i=0; i<net->numOuts; i++) { // this check works b/c we know this is last op in list if( net->outs[i].target >= x ) { if( net->outs[i].target < y) { net_disconnect(i); } else { /// this should take care of both param and op input targets. net_connect(i, net->outs[i].target - op->numInputs); } } } // erase input nodes while(x < y) { net_init_inode(x++); } // store the global index of the first output x = net_op_out_idx(opIdx, 0); y = x + op->numOutputs; // erase output nodes while(x < y) { net_init_onode(x++); } net->numIns -= op->numInputs; net->numOuts -= op->numOutputs; net->opPoolOffset -= op_registry[op->type].size; net->numOps -= 1; // FIXME: shift preset param data and connections to params, // since they share an indexing list with inputs and we just changed it. for(i=0; i<NET_PRESETS_MAX; ++i) { // shift parameter nodes in preset data for(j=0; j<net->numParams; ++j) { // this was the old param index idxOld = j + numInsSave; // copy to new param index idxNew = idxOld - ins; presets[i].ins[idxNew].value = presets[i].ins[idxOld].value; presets[i].ins[idxNew].enabled = presets[i].ins[idxOld].enabled; // clear the old data. presets[i].ins[idxOld].enabled = 0; presets[i].ins[idxOld].value = 0; } } app_resume(); return 0; }