diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index a007a33..ccacdba 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -292,15 +292,13 @@ export class SoundEvent extends AudibleEvent { out = (): void => { if (this.values.chord) { - this.values.chord.forEach((obj: {[key: string]: number}) => { - const copy = {...this.values}; + this.values.chord.forEach((obj: { [key: string]: number }) => { + const copy = { ...this.values }; copy.freq = obj.freq - // This is pure non-sense but I need to adapt somehow - superdough(copy, copy.dur*2, copy.dur); + superdough(copy, 0.25, this.values.dur); }); } else { - // This is pure non-sense but I need to adapt somehow - superdough(this.values, this.values.dur * 2, this.values.dur); + superdough(this.values, 0.25, this.values.dur); } }; } diff --git a/src/classes/ZPlayer.ts b/src/classes/ZPlayer.ts index 7a03692..4c3a862 100644 --- a/src/classes/ZPlayer.ts +++ b/src/classes/ZPlayer.ts @@ -101,28 +101,26 @@ export class Player extends Event { this.skipIndex = 0; } - // Main logic - const howAboutNow = - // If pattern is just starting - (this.notStarted() && - (this.pulse() === 0 || this.origin() >= this.nextBeatInTicks()) && - this.origin() >= this.waitTime) || - // If pattern is already playing - (this.current && - this.pulseToSecond(this.origin()) >= - this.pulseToSecond(this.lastCallTime) + - this.current.duration * - 4 * - this.pulseToSecond(this.app.api.ppqn()) && - this.origin() >= this.waitTime); + const patternIsStarting = (this.notStarted() && + (this.pulse() === 0 || this.origin() >= this.nextBeatInTicks()) && + this.origin() >= this.waitTime); + + const timeToPlayNext = (this.current && + this.pulseToSecond(this.origin()) >= + this.pulseToSecond(this.lastCallTime) + + this.pulseToSecond(this.current.duration*4*this.app.clock.ppqn) && + this.origin() >= this.waitTime); + // If pattern is starting or it's time to play next event + const areWeThereYet = patternIsStarting || timeToPlayNext; + // Increment index of how many times call is skipped - this.skipIndex = howAboutNow ? 0 : this.skipIndex + 1; + this.skipIndex = areWeThereYet ? 0 : this.skipIndex + 1; // Increment index of how many times sound/midi have been called - this.index = howAboutNow ? this.index + 1 : this.index; + this.index = areWeThereYet ? this.index + 1 : this.index; - if (howAboutNow && this.notStarted()) { + if (areWeThereYet && this.notStarted()) { this.initCallTime = this.app.clock.pulses_since_origin; } @@ -130,12 +128,14 @@ export class Player extends Event { this.startCallTime = this.app.clock.pulses_since_origin; } - return howAboutNow; + return areWeThereYet; }; sound(name: string) { + if (this.areWeThereYet()) { const event = this.next() as Pitch | Chord | ZRest; + const noteLengthInSeconds = this.app.clock.convertPulseToSecond(event.duration*4*this.app.clock.ppqn); if (event instanceof Pitch) { const obj = event.getExisting( "freq", @@ -145,7 +145,7 @@ export class Player extends Event { "octave", "parsedScale" ); - obj.dur = event.duration; + obj.dur = noteLengthInSeconds; return new SoundEvent(obj, this.app).sound(name); } else if (event instanceof Chord) { const pitches = event.pitches.map((p) => { @@ -158,7 +158,7 @@ export class Player extends Event { "parsedScale" ); }); - return new SoundEvent({dur: event.duration}, this.app).chord(pitches).sound(name); + return new SoundEvent({dur: noteLengthInSeconds}, this.app).chord(pitches).sound(name); } else if (event instanceof ZRest) { return RestEvent.createRestProxy(event.duration, this.app); } diff --git a/src/examples/excerpts.ts b/src/examples/excerpts.ts index 8c916de..fb29854 100644 --- a/src/examples/excerpts.ts +++ b/src/examples/excerpts.ts @@ -25,22 +25,6 @@ beat(.5) :: sound('STA6').cut(1).vel(0.4) binrhythm(.5, 50) :: sound('shaker').out() binrhythm(.5, 52) :: sound('808bd').n(3).out() rhythm(.25, 6, 8) :: sound('808sd').out()`, - `// Numerology - Bubobubobubo -bpm(130); -let mel = [ - "0.125 _ (0 3 7 0 3 5 0 3 9)+(0 2)", "0.125 (0 7 0 10 0 5)+(0 3)", - "0.125 (0 3 7 0 3 5 0 3 9)+(0 2)", "0.125 (0 2 4 5 9 10)+(0 2)", -].beat(4); -z0(mel) - .scale('minor').sound('wt_piano').cutoff(800 + usine(.5) * 5000) - .fmi([2, 4, 8].beat(2)).fmh(flip(2) ? 2 : 4) - .delay(bpm() / 60 / 9).delayt(0.25).delayfb(0.5) - .fmsus(0.3).fmrel(0.3).rel(rand(0.5,0.8)) - .sus(rand(0.05, 0.1)).out(); -beat(1) :: sound(flip(2) ? 'kick' : ['sd', 'cp'].beat(3)).out(); -beat([.25, .5].beat(4)) :: flip(6) && sound('dr') - .room(0.85).size(0.85).vel($(1) % 10 / 8) - .n([1, 2, 7].pick()).out();`, `// Harmonic Leaps and Gaps -- Bubobubobubo let oscillation = quant(usine(.25) * 20, [35, 40, 38, 50, 55]); let tonal = [0, 5, 0, 0, 7].palindrome().bar() + 40 - 24; @@ -219,4 +203,22 @@ beat([.25,.125, .5].beat(4))::snd('arpy:4') .resonance(5).gain(0.4).end(0.8).room(0.9).size(0.9).n(3).out(); beat(.5) :: snd('arpy').note([30, 33, 35].repeatAll(4).beat(1) - [24,12].beat(0.5)) .cutoff(500).lpadsr(8, 0.05, .125, 0, 0).out()`, + /* + `// Numerology - Bubobubobubo +bpm(130); +let mel = [ + "0.125 _ (0 3 7 0 3 5 0 3 9)+(0 2)", "0.125 (0 7 0 10 0 5)+(0 3)", + "0.125 (0 3 7 0 3 5 0 3 9)+(0 2)", "0.125 (0 2 4 5 9 10)+(0 2)", +].beat(4); +z0(mel) + .scale('minor').sound('wt_piano').cutoff(800 + usine(.5) * 5000) + .fmi([2, 4, 8].beat(2)).fmh(flip(2) ? 2 : 4) + .delay(bpm() / 60 / 9).delayt(0.25).delayfb(0.5) + .fmsus(0.3).fmrel(0.3).rel(rand(0.5,0.8)) + .sus(rand(0.05, 0.1)).out(); +beat(1) :: sound(flip(2) ? 'kick' : ['sd', 'cp'].beat(3)).out(); +beat([.25, .5].beat(4)) :: flip(6) && sound('dr') + .room(0.85).size(0.85).vel($(1) % 10 / 8) + .n([1, 2, 7].pick()).out();`, + */ ];