Skip to content

Commit

Permalink
feat(Trigger): added bang to notify other nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
xiduzo committed Dec 14, 2024
1 parent c46bb76 commit e4712a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export function Trigger(props: Props) {
<NodeContainer {...props}>
<Value />
<Settings />
<Handle type="target" position={Position.Left} id="signal" offset={-0.5} />
<Handle type="source" position={Position.Bottom} id="change" />
<Handle type="target" position={Position.Left} id="signal" />
<Handle type="source" position={Position.Right} id="bang" />
</NodeContainer>
);
}
Expand Down
18 changes: 0 additions & 18 deletions packages/components/src/components/BaseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,4 @@ export class BaseComponent<T> {
value: error,
});
}

/**
* @TODO apparently this doesn't work
*
* bang the output 'change' gate
*/
public bang() {
let value: number = 1.0;
this.eventEmitter.emit('change', JSON.stringify(value));
}

/**
* "unbang"
*/
public quiet() {
let value: number = 0.0;
this.eventEmitter.emit('change', JSON.stringify(value));
}
}
19 changes: 8 additions & 11 deletions packages/components/src/components/Trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { BaseComponent, BaseComponentOptions } from './BaseComponent';

export type TriggerBehaviour = 'increasing' | 'exact' | 'decreasing';

//export type WaveformType = 'sinus' | 'square' | 'sawtooth' | 'triangle' | 'random';

export type TriggerData = {
behaviour: TriggerBehaviour;
threshold: number;
Expand Down Expand Up @@ -87,27 +85,26 @@ export class Trigger extends BaseComponent<TriggerValueType> {

switch (this.options.behaviour) {
case 'increasing': {
retval = this.checkIncreasing(value);
retval = this.checkIncreasing(Number(value));
//console.log(`[>] trigger ${this.value} < ${value}`);
break;
}
case 'exact': {
retval = this.value === value ? true : false;
retval = this.value === Number(value);
//console.log(`[=] trigger ${this.value} = ${value}`);
break;
}
case 'decreasing': {
retval = this.checkDecreasing(value); //this.value > value ? true : false;
retval = this.checkDecreasing(Number(value)); //this.value > value ? true : false;
//console.log(`[<] trigger ${this.value} > ${value}`);
break;
}
}

if (retval) {
this.value = 1.0; // not ideal, I don't really want to send a specific value here but rather a gate bang
setTimeout(() => {
this.value = 0.0;
}, this.options.duration);
}
this.value = Number(value);

if (!retval) return;

this.eventEmitter.emit('bang', this.value);
} // input()
} // Trigger component

0 comments on commit e4712a0

Please sign in to comment.