static LispObjectPtr lisp_Saw(LispInterpreter *L, LispObjectPtr args, LispObjectPtr env, void *data) { auto saw = MakeSignal(L, L->MakeCFunction(lisp_StepSaw, nullptr)); PutSlot(L, saw, L->SymbolRef("freq"), L->MakeNumber(0)); PutSlot(L, saw, L->SymbolRef("out"), L->MakeNumber(0)); return saw; }
static LispObjectPtr MakeWavetableOscillator(LispInterpreter *L, LispObjectPtr stepFun) { auto sig = MakeSignal(L, stepFun); PutSlot(L, sig, L->SymbolRef("freq"), L->MakeNumber(0)); PutSlot(L, sig, L->SymbolRef("index"), L->MakeNumber(0)); PutSlot(L, sig, L->SymbolRef("out"), L->MakeNumber(0)); return sig; }
LispObjectPtr lisp_Toggle(LispInterpreter *L, LispObjectPtr args, LispObjectPtr env, void *data) { auto toggle = MakeSignal(L, L->MakeCFunction(lisp_StepToggle, nullptr)); PutSlot(L, toggle, L->SymbolRef("event"), L->Nil); PutSlot(L, toggle, L->SymbolRef("a"), L->MakeNumber(0)); PutSlot(L, toggle, L->SymbolRef("b"), L->MakeNumber(1)); PutSlot(L, toggle, L->SymbolRef("selected"), L->SymbolRef("a")); PutSlot(L, toggle, L->SymbolRef("out"), GetSlot(L, toggle, L->SymbolRef("a"))); return toggle; }
void Run() { cout << "Example 1 - Creating subject-bound observers (v2)" << endl; // Outer scope { // Unbound observer ObserverT obs; // Inner scope { auto mySignal = MakeSignal(x, [] (int x) { return x; } ); // Move-assign to obs obs = Observe(mySignal, [] (int mySignal) { cout << mySignal << endl; }); // The node linked to mySignal is now also owned by obs x <<= 2; // output: 2 } // ~Inner scope // mySignal was destroyed, but as long as obs exists and is still // attached to the signal node, this signal node won't be destroyed x <<= 3; // output: 3 } // ~Outer scope // obs was destroyed // -> the signal node is no longer owned by anything and is destroyed // -> the observer node is destroyed as it was bound to the subject x <<= 4; // no ouput cout << endl; }
LispObjectPtr MakeEventRelaySignal(LispInterpreter *L) { auto signal = MakeSignal(L, L->MakeCFunction(lisp_StepEventRelay, nullptr)); PutSlot(L, signal, L->SymbolRef("out"), L->Nil); return signal; }
static LispObjectPtr lisp_MakeSignal(LispInterpreter *L, LispObjectPtr args, LispObjectPtr env, void *data) { return MakeSignal(L, L->Car(args)); }