Skip to content

Commit

Permalink
sample.js -> sample-set.js
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Sep 25, 2023
1 parent 7809165 commit 4aceea9
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 81 deletions.
2 changes: 1 addition & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Envelope from './nodes/envelope.js';
import Tick from './nodes/tick.js';
import Recorder from './nodes/recorder.js';
import Sink from './nodes/sink.js';
import Sample from './nodes/sample.js';
import Sample from './nodes/sample-set.js';
import Tone from './nodes/tone.js';
import Noise from './nodes/noise.js';
import Instrument from './nodes/instrument.js';
Expand Down
4 changes: 2 additions & 2 deletions modules/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Instrument from '../nodes/instrument.js';
import Metronome from '../nodes/metronome.js';
import MixNode from '../nodes/mix.js';
import SampleNode from '../nodes/sample.js';
import SampleNode from '../nodes/sample-set.js';
*/

/*
Expand Down Expand Up @@ -45,7 +45,7 @@ import SampleNode from '../nodes/sample.js';
// ../nodes/mix.js
'mix': MixNode,
// ../nodes/sample.js
// ../nodes/sample-set.js
'sample': SampleNode
*/

Expand Down
81 changes: 19 additions & 62 deletions modules/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import overload from '../../fn/modules/overload.js';
import Pool from '../../fn/modules/pool.js';
import remove from '../../fn/modules/remove.js';
import toType from '../../fn/modules/to-type.js';
import { bytesToSignedFloat } from '../../midi/modules/maths.js';
import { bytesToSignedFloat } from '../../midi/modules/maths.js';
import { toType as toTypeMIDI } from '../../midi/modules/data.js';
import parseFloat64 from './parse/parse-float-64.js';
import parseFloat32 from './parse/parse-float-32.js';
Expand Down Expand Up @@ -101,8 +101,6 @@ const define = Object.defineProperties;
const getData = get('data');


// ---

const pitchBendRange = 2;

const lengths = {
Expand All @@ -117,6 +115,7 @@ const lengths = {
'meter': 4,
'rate': 3,
'param': 5,
'pitch': 3,
'log': 3,
default: 5
};
Expand All @@ -125,16 +124,21 @@ function pitchToFloat(message) {
return bytesToSignedFloat(message[1], message[2]) * pitchBendRange;
}




/**
Event(time, type, ...)
A constructor for event objects for internal use.
**/

const tuning = 440; /* TEMP */
const constructEventType = overload(arg(1), {
// Event types
//
// [time, "rate", number, curve]
// [time, "meter", numerator, denominator]
// [time, "note", number, velocity, duration]
// [time, "noteon", number, velocity]
// [time, "noteoff", number]
// [time, "param", name, value, curve]
// [time, "pitch", semitones]
// [time, "chord", root, mode, duration]
// [time, "log", value]
// [time, "sequence", name || events, target, duration, transforms...]

'note': function() {
// frequency, gain, duration
this[2] = parseNote(arguments[2], tuning);
Expand Down Expand Up @@ -182,6 +186,10 @@ const constructEventType = overload(arg(1), {
}
},

'pitch': function() {
this[2] = parseFloat64(arguments[2]);
},

'meter': function() {
// numerator, denominator
this[2] = parseInt(arguments[2], 10);
Expand Down Expand Up @@ -356,54 +364,3 @@ export function getDuration(e) {
e[1] === 'sequence' ? e[4] :
undefined ;
}


/**
isValidEvent(event)
Checks event for type and length to make sure it conforms to an event
type signature.
**/

// Event types
//
// [time, "rate", number, curve]
// [time, "meter", numerator, denominator]
// [time, "note", number, velocity, duration]
// [time, "noteon", number, velocity]
// [time, "noteoff", number]
// [time, "param", name, value, curve]
// [time, "pitch", semitones]
// [time, "chord", root, mode, duration]
// [time, "log", value]
// [time, "sequence", name || events, target, duration, transforms...]

export const isValidEvent = overload(get(1), {
note: (event) => event[4] !== undefined,
noteon: (event) => event[3] !== undefined,
noteoff: (event) => event[2] !== undefined,
'start': (event) => event[3] !== undefined,
'stop': (event) => event[2] !== undefined,
'sequence': (event) => event[4] !== undefined,
'sequence-start': (event) => event[3] !== undefined,
'sequence-stop': (event) => event[2] !== undefined,
meter: (event) => event[3] !== undefined,
rate: (event) => event[2] !== undefined,
param: (event) => event[4] !== undefined,
log: (event) => event[2] !== undefined,
default: (event) => (typeof event[0] === 'number' && typeof event[1] === 'string')
});

export const eventValidationHint = overload(get(1), {
note: (event) => 'Should be of the form [time, "note", number, velocity, duration]',
noteon: (event) => 'Should be of the form [time, "noteon", note, velocity]',
noteoff: (event) => 'Should be of the form [time, "noteoff", note]',
'start': (event) => 'Should be of the form [time, "start", note, level]',
'stop': (event) => 'Should be of the form [time, "stop", note]',
'sequence': (event) => 'Should be of the form [time, "sequence", id, target, duration]',
'sequence-start': (event) => 'Should be of the form [time, "sequence-start", id, target]',
'sequence-stop': (event) => 'Should be of the form [time, "sequence-stop", id]',
meter: (event) => 'Should be of the form [time, "meter", numerator, denominator]',
rate: (event) => 'Should be of the form [time, "rate", number, curve]',
log: (event) => 'Should be of the form [time, "log", string]',
default: (event) => 'Probably should be of the form [time, name, value, curve, duration]'
});
2 changes: 1 addition & 1 deletion modules/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { print } from './print.js';
import { getDejitterTime } from './context.js';
import Playable, { IDLE, PLAYING } from './playable.js';
import { automate, getValueAtTime } from './automate.js';
import { isRateEvent, getDuration, isValidEvent, eventValidationHint } from './event.js';
import { isRateEvent, getDuration } from './event.js';
import { timeAtBeatOfEvents } from './sequencer/location.js';
import parseEvent from './parse/parse-event.js';
import parseEvents from './parse/parse-events.js';
Expand Down
10 changes: 1 addition & 9 deletions modules/sequencer/sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ function processFrame(sequence, t2, b1, b2, events, latest, stopbuffer, buffer)
while (++n < buffer.length) {
let event = buffer[n];

/*if (!isValidEvent(event)) {
throw new Error('Invalid event ' + JSON.stringify(event) + '. ' + eventValidationHint(event));
}*/

// Deal with events that have duration by creating -start and -stop events
const duration = getDuration(event);

Expand Down Expand Up @@ -192,11 +188,7 @@ function processFrame(sequence, t2, b1, b2, events, latest, stopbuffer, buffer)
function readBufferEvent(sequence, stopbuffer, buffer, n) {
const event = buffer[n];
const time = sequence.timeAtBeat(event[0]);
/*
if (!isValidEvent(event)) {
throw new Error('Invalid event ' + JSON.stringify(event) + '. ' + eventValidationHint(event));
}
*/

// Syphon off events, create and start child sequences
if (event[1] === 'sequence-start') {
// This may extend the buffer with more events
Expand Down
2 changes: 1 addition & 1 deletion nodes/looper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Privates from '../../fn/modules/privates.js';
import NodeGraph from './graph.js';
import Playable from './play-node.js';
import Recorder from './recorder.js';
import Sample from './sample.js';
import Sample from './sample-set.js';
import { assignSettings } from '../modules/assign-settings.js';
import { automate } from '../modules/automate.js';
import { getInputLatency, getOutputLatency } from '../modules/context.js';
Expand Down
2 changes: 1 addition & 1 deletion nodes/sample.js → nodes/sample-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ An AudioParam that modifies the frequency in cents.

import Privates from '../../fn/modules/privates.js';
import { frequencyToFloat } from '../../midi/modules/data.js';
import { dB24, dB30, dB60 } from '../modules/constants.js';
import { dB24, dB30, dB60 } from '../modules/constants.js';
import { requestBuffer } from '../modules/request-buffer.js';
import { requestData } from '../modules/request-data.js';
import { assignSettingz__ } from '../modules/assign-settings.js';
Expand Down
2 changes: 1 addition & 1 deletion nodes/test/instrument-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import context from '../../modules/context.js';
import Instrument from '../instrument.js';

import Mix from '../mix.js';
import Sample from '../sample.js';
import Sample from '../sample-set.js';
import Tone from '../tone.js';
import { constructors } from '../graph.js';

Expand Down
2 changes: 1 addition & 1 deletion nodes/test/sample-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import run from '../../../fn/modules/test.js';
import toGain from '../../../fn/modules/to-gain.js';
import context from '../../modules/context.js';
import Sample from '../sample.js';
import Sample from '../sample-set.js';

import { floatToFrequency } from '../../../midi/module.js';

Expand Down
2 changes: 1 addition & 1 deletion nodes/test/voice-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import context from '../../modules/context.js';
import Voice from '../voice.js';

import Mix from '../mix.js';
import Sample from '../sample.js';
import Sample from '../sample-set.js';
import { constructors } from '../graph.js';

const assign = Object.assign;
Expand Down
2 changes: 1 addition & 1 deletion nodes/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logGroup, logGroupEnd } from './print.js';
import Privates from '../../fn/modules/privates.js';
import NodeGraph from './graph.js';
import Recorder from './recorder.js';
import Sample from './sample.js';
import Sample from './sample-set.js';
import { automate } from '../modules/automate.js';

const DEBUG = window.DEBUG;
Expand Down

0 comments on commit 4aceea9

Please sign in to comment.