Skip to content

Commit

Permalink
Give tick context
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Sep 29, 2023
1 parent 18f4af1 commit 45afcec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
9 changes: 0 additions & 9 deletions nodes/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,10 @@ import Pool from '../modules/pool.js';
import { assignSettingz__ } from '../modules/assign-settings.js';
import { connect, disconnect } from '../modules/connect.js';

import Mix from './mix.js';
import Samples from './sample-set.js';
import Tone from './tone.js';

const DEBUG = window.DEBUG;
const assign = Object.assign;
const define = Object.defineProperties;

// Register node constructors in NodeGraph
NodeGraph.register('mix', Mix);
NodeGraph.register('samples', Samples);
NodeGraph.register('tone', Tone);

export const config = {
tuning: 440
};
Expand Down
30 changes: 13 additions & 17 deletions nodes/tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ A float?? Todo.
An AudioParam representing output gain.
**/

import noop from '../../fn/modules/noop.js';
import noop from '../../fn/modules/noop.js';
import { floatToFrequency, toNoteNumber } from '../../midi/modules/data.js';
import { dB48 } from '../modules/constants.js';

var assign = Object.assign;
const assign = Object.assign;


// Define
Expand All @@ -47,17 +47,17 @@ export const defaults = {

// Tick

export default function Tick(audio, options) {
export default function Tick(context, options) {
if (!Tick.prototype.isPrototypeOf(this)) {
return new Tick(audio, options);
return new Tick(context, options);
}

var settings = assign({}, defaults, options);

var oscillator = audio.createOscillator();
var filter = audio.createBiquadFilter();
var gain = audio.createGain();
var output = audio.createGain();
var oscillator = context.createOscillator();
var filter = context.createBiquadFilter();
var gain = context.createGain();
var output = context.createGain();
//var merger = audio.createChannelMerger(2);

//NodeGraph.call(this, {
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function Tick(audio, options) {
}

oscillator.type = 'square';
oscillator.frequency.setValueAtTime(300, audio.currentTime);
oscillator.frequency.setValueAtTime(300, context.currentTime);
oscillator.start();
oscillator.connect(filter);

Expand All @@ -128,8 +128,8 @@ export default function Tick(audio, options) {
//output.connect(merger, 0, 0);
//output.connect(merger, 0, 1);

this.gain = output.gain;

this.context = context;
this.gain = output.gain;
this.resonance = settings.resonance;
this.decay = settings.decay;
//this.gain = settings.gain;
Expand All @@ -138,12 +138,8 @@ export default function Tick(audio, options) {
.start(time, note, velocity)
Todo: move parameters to be properties of tick object, echoing other signal generators
**/
this.start = function(time, number, level) {
var frequency = typeof number === 'string' ?
floatToFrequency(440, toNoteNumber(number)) :
floatToFrequency(440, number) ;

schedule(time || audio.currentTime, frequency, level, this.decay, this.resonance);
this.start = function(time, frequency, level) {
schedule(time || context.currentTime, frequency, level, this.decay, this.resonance);
return this;
};

Expand Down
11 changes: 11 additions & 0 deletions nodes/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ import { assignSettingz__ } from '../modules/assign-settings.js';
import { floatToFrequency, toNoteNumber } from '../../midi/modules/data.js';
import { create } from '../modules/constructors.js';

import Mix from './mix.js';
import Samples from './sample-set.js';
import Tick from './tick.js';
import Tone from './tone.js';

// Register node constructors in NodeGraph
NodeGraph.register('mix', Mix);
NodeGraph.register('samples', Samples);
NodeGraph.register('tick', Tick);
NodeGraph.register('tone', Tone);

const assign = Object.assign;
const define = Object.defineProperties;
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
Expand Down

0 comments on commit 45afcec

Please sign in to comment.