// toggle preset inclusion for output u8 net_toggle_out_preset(u32 id) { u8 tmp = preset_out_enabled(preset_get_select(), id) ^ 1; // net->outs[id].preset ^= 1; // return net->outs[id].preset; print_dbg("\r\n toggled output-preset_enable"); print_dbg(", out: "); print_dbg_ulong(id); print_dbg(", flag: "); print_dbg_ulong(tmp); preset_get_selected()->outs[id].enabled = tmp; return tmp; }
// redraw based on provisional preset seleciton void redraw_outs_preset (void) { // s32 max = net_num_outs() - 1; u8 i=0; u8 idx = *pageSelect - 3; u8 fg; u8 enabled; s16 target; s16 targetOpIdx = -1; s16 srcOpIdx; s32 preSel = preset_get_select(); // print_dbg("\r\n redraw_outs_preset()"); while(i<8) { region_fill(lineRegion, 0x0); if(idx >= net_num_outs() ) { return; } enabled = preset_out_enabled(preSel, idx); if(enabled) { // if it's enabled, show the preset's target (including if blank) target = preset_get_selected()->outs[idx].target; srcOpIdx = net_out_op_idx(idx); targetOpIdx = net_in_op_idx(target); if(target >= 0) { //// output has target // the network doesn't actually execute connections from an op to itself. // reflect this in UI by dimming this line if(targetOpIdx == srcOpIdx) { fg = 0x5; } // render output clearln(); appendln_idx_lj(srcOpIdx); appendln_char('.'); appendln( net_op_name(srcOpIdx)); appendln_char('/'); appendln( net_out_name(idx) ); endln(); font_string_region_clip(lineRegion, lineBuf, 2, 0, fg, 0); // render target targetOpIdx = net_in_op_idx(target); clearln(); appendln("-> "); if(targetOpIdx >= 0) { // target is operator input appendln_idx_lj(net_in_op_idx(target)); appendln_char('.'); appendln( net_op_name(net_in_op_idx(target)) ); appendln_char('/'); appendln( net_in_name(target) ); } else { // target is parameter input appendln_idx_lj( (int)net_param_idx(target)); appendln_char('.'); appendln( net_in_name(target)); } endln(); font_string_region_clip(lineRegion, lineBuf, 60, 0, fg, 0); clearln(); } else { //// no target // render output clearln(); appendln_idx_lj(net_out_op_idx(idx)); appendln_char('.'); appendln( net_op_name(net_out_op_idx(idx))); appendln_char('/'); appendln( net_out_name(idx) ); endln(); font_string_region_clip(lineRegion, lineBuf, 2, 0, fg, 0); } // draw something to indicate preset inclusion if(net_get_out_preset(idx)) { font_string_region_clip(lineRegion, ".", 126, 0, fg, 0); } } else { // not enabled, draw as normal with dim coloring render_line(idx, 0x5); } render_to_scroll_line(i, 0); ++i; ++idx; } draw_preset_name(); }
// attempt to allocate a new operator from the static memory pool, return index s16 net_add_op(op_id_t opId) { u16 ins, outs; int i, j; int idxOld, idxNew; op_t* op; s32 numInsSave = net->numIns; s32 numOutsSave = net->numOuts; print_dbg("\r\n adding operator; old input count: "); print_dbg_ulong(numInsSave); if (net->numOps >= NET_OPS_MAX) { return -1; } print_dbg(" , op class: "); print_dbg_ulong(opId); print_dbg(" , size: "); print_dbg_ulong(op_registry[opId].size); if (op_registry[opId].size > NET_OP_POOL_SIZE - net->opPoolOffset) { print_dbg("\r\n op creation failed; op memory pool is exhausted."); return -1; } print_dbg(" ; allocating... "); op = (op_t*)((u8*)net->opPool + net->opPoolOffset); // use the class ID to initialize a new object in scratch print_dbg(" ; initializing... "); op_init(op, opId); ins = op->numInputs; outs = op->numOutputs; if (ins > (NET_INS_MAX - net->numIns)) { print_dbg("\r\n op creation failed; too many inputs in network."); return -1; } if (outs > (NET_OUTS_MAX - net->numOuts)) { print_dbg("\r\n op creation failed; too many outputs in network."); return -1; } // add op pointer to list net->ops[net->numOps] = op; // advance offset for next allocation net->opPoolOffset += op_registry[opId].size; //---- add inputs and outputs to node list for(i=0; i<ins; ++i) { net->ins[net->numIns].opIdx = net->numOps; net->ins[net->numIns].opInIdx = i; ++(net->numIns); } for(i=0; i<outs; i++) { net->outs[net->numOuts].opIdx = net->numOps; net->outs[net->numOuts].opOutIdx = i; net->outs[net->numOuts].target = -1; ++(net->numOuts); } if(net->numOps > 0) { // if we added input nodes, need to adjust connections to DSP params for(i=0; i < numOutsSave; i++) { /* print_dbg("\r\n checking output no. "); */ /* print_dbg_ulong(i); */ /* print_dbg(" ; target: "); */ /* print_dbg_ulong(net->outs[i].target); */ if(net->outs[i].target >= numInsSave) { /* print_dbg("\r\n adjusting target after op creation; old op count: "); */ /* print_dbg_ulong(net->numOps); */ /* print_dbg(" , output index: "); */ /* print_dbg_ulong(i); */ /* print_dbg(" , current target "); */ /* print_dbg_ulong(net->outs[i].target); */ /* print_dbg(" , count of inputs in new op: "); */ /* print_dbg_ulong(ins); */ // preset target, add offset for new inputs net_connect(i, net->outs[i].target + ins); } /// do the same in all presets! for(j=0; j<NET_PRESETS_MAX; j++) { if(preset_out_enabled(j, i)) { s16 tar = presets[j].outs[i].target; if(tar >= numInsSave) { tar = tar + ins; presets[j].outs[i].target = tar; } } } // preset loop } // outs loop for(i=0; i<NET_PRESETS_MAX; i++) { // shift parameter nodes in preset data for(j=net->numParams - 1; j>=0; j--) { // this was the old param index idxOld = j + numInsSave; // copy to new param index idxNew = idxOld + ins; if(idxNew >= PRESET_INODES_COUNT) { print_dbg("\r\n out of preset input nodes in new op creation! "); continue; } else { presets[i].ins[idxNew].value = presets[i].ins[idxOld].value; presets[i].ins[idxNew].enabled = presets[i].ins[idxOld].enabled; // clear the old data. it may correspond to new operator inputs. presets[i].ins[idxOld].enabled = 0; presets[i].ins[idxOld].value = 0; } } } } ++(net->numOps); return net->numOps - 1; }
// toggle preset inclusion for output u8 net_toggle_out_preset(u32 id) { u8 tmp = preset_out_enabled(preset_get_select(), id) ^ 1; preset_get_selected()->outs[id].enabled = tmp; return tmp; }