Adding even more examples
This commit is contained in:
34
src/API.ts
34
src/API.ts
@ -316,7 +316,7 @@ export class UserAPI {
|
|||||||
player = new Player(input, options, this.app);
|
player = new Player(input, options, this.app);
|
||||||
this.app.api.patternCache.set(key, player);
|
this.app.api.patternCache.set(key, player);
|
||||||
}
|
}
|
||||||
if(player) player.updateLastCallTime();
|
if (player) player.updateLastCallTime();
|
||||||
return player;
|
return player;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1192,4 +1192,36 @@ export class UserAPI {
|
|||||||
// is evaluated. This is useful for slowing down the script, or speeding it up. The default
|
// is evaluated. This is useful for slowing down the script, or speeding it up. The default
|
||||||
// would be 1.0, which is the current rate (very speedy).
|
// would be 1.0, which is the current rate (very speedy).
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// Legacy functions
|
||||||
|
// =============================================================
|
||||||
|
|
||||||
|
public divseq = (...args: any): any => {
|
||||||
|
const chunk_size = args[0]; // Get the first argument (chunk size)
|
||||||
|
const elements = args.slice(1); // Get the rest of the arguments as an array
|
||||||
|
const timepos = this.epulse();
|
||||||
|
const slice_count = Math.floor(
|
||||||
|
timepos / Math.floor(chunk_size * this.ppqn())
|
||||||
|
);
|
||||||
|
return elements[slice_count % elements.length];
|
||||||
|
};
|
||||||
|
|
||||||
|
public seqbeat = <T>(...array: T[]): T => {
|
||||||
|
/**
|
||||||
|
* Returns an element from an array based on the current beat.
|
||||||
|
*
|
||||||
|
* @param array - The array of values to pick from
|
||||||
|
*/
|
||||||
|
return array[this.ebeat() % array.length];
|
||||||
|
};
|
||||||
|
|
||||||
|
public seqbar = <T>(...array: T[]): T => {
|
||||||
|
/**
|
||||||
|
* Returns an element from an array based on the current bar.
|
||||||
|
*
|
||||||
|
* @param array - The array of values to pick from
|
||||||
|
*/
|
||||||
|
return array[(this.app.clock.time_position.bar + 1) % array.length];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -705,14 +705,43 @@ Music really comes to life when you start playing with algorithmic patterns. The
|
|||||||
|
|
||||||
JavaScript is using [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) as a data structure for lists. Topos is extending them with custom methods that allow you to enter softly into a universe of musical patterns. These methods can often be chained to compose a more complex expression: <icode>[1, 2, 3].repeatOdd(5).palindrome().beat()</icode>.
|
JavaScript is using [Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) as a data structure for lists. Topos is extending them with custom methods that allow you to enter softly into a universe of musical patterns. These methods can often be chained to compose a more complex expression: <icode>[1, 2, 3].repeatOdd(5).palindrome().beat()</icode>.
|
||||||
|
|
||||||
- <icode>div(division: number)</icode>:
|
- <icode>div(division: number)</icode>: this method will return the next value in the list every _n_ pulses. By default, <icode>1</icode> equals to one beat but integer and floating point number values are supported as well. This method is extremely powerful and can be used for many different purposes. Check out the examples.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"div is the greatest method ever",
|
"Light drumming",
|
||||||
`
|
`// Every bar, use a different rhythm
|
||||||
|
mod([1, 0.75].div(4)) :: sound('cp').out()
|
||||||
|
mod([0.5, 1].div(4)) :: sound('kick').out()
|
||||||
|
mod(2)::snd('snare').shape(.5).out()
|
||||||
`,
|
`,
|
||||||
true
|
true
|
||||||
)}
|
)}
|
||||||
|
${makeExample(
|
||||||
|
"Using div to create arpeggios",
|
||||||
|
`// Arpeggio using pulse divisions
|
||||||
|
mod([.5, .25].div(2)) :: sound('sine')
|
||||||
|
.hcutoff(400)
|
||||||
|
.fmi([1,2].div(8))
|
||||||
|
.fmh([0.5,0.25,1].div(2))
|
||||||
|
.note([50,53,57].div(.25) + [12,24].div(2))
|
||||||
|
.sustain([0.25, 0.5].div(8))
|
||||||
|
.room(0.9).size(0.5)
|
||||||
|
.delay(0.25).delayt([0.5,0.25].div(16))
|
||||||
|
.delayfb(0.5)
|
||||||
|
.out()
|
||||||
|
`,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
${makeExample(
|
||||||
|
"Cool ambiance",
|
||||||
|
`mod(.5) :: snd(['kick', 'hat'].div(4)).out()
|
||||||
|
mod([2,4].div(2)) :: snd('shaker').delay(.5).delayfb(.75).delayt(0.125).out()
|
||||||
|
div(2)::mod(1)::snd('clap').out()
|
||||||
|
div(4)::mod(2)::snd('pad').n(2).shape(.5).orbit(2).room(0.9).size(0.9).release(0.5).out()
|
||||||
|
`,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- <icode>beat()</icode>: returns the index of the list corresponding to current beat (with wrapping). This allows you to return a different value for each beat.
|
- <icode>beat()</icode>: returns the index of the list corresponding to current beat (with wrapping). This allows you to return a different value for each beat.
|
||||||
|
|||||||
Reference in New Issue
Block a user