OscillatorEditor.js 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { ObjectNode, SelectInput, LabelElement } from '../../libs/flow.module.js';
  2. import { OscNode, FloatNode } from '../../renderers/nodes/Nodes.js';
  3. const NULL_VALUE = new FloatNode();
  4. export class OscillatorEditor extends ObjectNode {
  5. constructor() {
  6. const node = new OscNode( OscNode.SINE, NULL_VALUE );
  7. super( 'Oscillator', 1, node, 250 );
  8. const methodInput = new SelectInput( [
  9. { name: 'Sine', value: OscNode.SINE },
  10. { name: 'Square', value: OscNode.SQUARE },
  11. { name: 'Triangle', value: OscNode.TRIANGLE },
  12. { name: 'Sawtooth', value: OscNode.SAWTOOTH }
  13. ] );
  14. methodInput.onChange( () => {
  15. node.method = methodInput.getValue();
  16. this.invalidate();
  17. } );
  18. const timeElement = new LabelElement( 'Time' ).setInput( 1 );
  19. timeElement.onConnect( () => {
  20. node.timeNode = timeElement.linkedExtra || NULL_VALUE;
  21. } );
  22. this.add( new LabelElement( 'Method' ).add( methodInput ) )
  23. .add( timeElement );
  24. }
  25. }