scribbletune 5.2.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +276 -22
  2. package/dist/browser.cjs +1183 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.js +1135 -1
  5. package/dist/browser.js.map +1 -1
  6. package/dist/cli.cjs +813 -0
  7. package/dist/{index.mjs → index.cjs} +225 -169
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +323 -0
  10. package/dist/index.d.ts +303 -350
  11. package/dist/index.js +524 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/scribbletune.global.js +1944 -0
  14. package/dist/scribbletune.global.js.map +1 -0
  15. package/package.json +32 -40
  16. package/dist/lib/arp.d.ts +0 -10
  17. package/dist/lib/browser-clip.d.ts +0 -14
  18. package/dist/lib/browser-index.d.ts +0 -7
  19. package/dist/lib/channel.d.ts +0 -61
  20. package/dist/lib/clip.d.ts +0 -2
  21. package/dist/lib/index.d.ts +0 -7
  22. package/dist/lib/midi.d.ts +0 -11
  23. package/dist/lib/progression.d.ts +0 -25
  24. package/dist/lib/session.d.ts +0 -14
  25. package/dist/lib/types/arp-params.d.ts +0 -6
  26. package/dist/lib/types/channel-params.d.ts +0 -92
  27. package/dist/lib/types/channel-pattern.d.ts +0 -24
  28. package/dist/lib/types/clip-params.d.ts +0 -104
  29. package/dist/lib/types/event-fn.d.ts +0 -7
  30. package/dist/lib/types/index.d.ts +0 -14
  31. package/dist/lib/types/note-object.d.ts +0 -6
  32. package/dist/lib/types/nvp.d.ts +0 -4
  33. package/dist/lib/types/play-params.d.ts +0 -15
  34. package/dist/lib/types/player-observer-fn.d.ts +0 -6
  35. package/dist/lib/types/progression-scale.d.ts +0 -2
  36. package/dist/lib/types/seq-fn.d.ts +0 -2
  37. package/dist/lib/types/sizzle-style.d.ts +0 -2
  38. package/dist/lib/types/synth-params.d.ts +0 -20
  39. package/dist/lib/types/tpd.d.ts +0 -15
  40. package/dist/lib/utils.d.ts +0 -56
  41. package/dist/scribbletune.js +0 -2
  42. package/dist/scribbletune.js.map +0 -1
@@ -0,0 +1,323 @@
1
+ export { chord, chords, scale as mode, scales as modes, scale, scales } from 'harmonics';
2
+
3
+ type SizzleStyle = 'sin' | 'cos' | 'rampUp' | 'rampDown';
4
+ type ProgressionScale = 'major' | 'minor' | 'M' | 'm';
5
+ type SeqFn = (time: string, el: string) => void;
6
+ /**
7
+ * Callback function triggered when channel has a new event.
8
+ * @param event - one of ['loaded', 'error']
9
+ * @param params - object with event data
10
+ */
11
+ type EventFn = (event: string, params: Record<string, unknown>) => void;
12
+ /**
13
+ * Callback function triggered when a note is played.
14
+ * @param params - object with player data
15
+ */
16
+ type PlayerObserverFn = (params: Record<string, unknown>) => void;
17
+ /** Recursive pattern element produced by expandStr */
18
+ type PatternElement = string | PatternElement[];
19
+ interface NVP<T> {
20
+ [key: string]: T;
21
+ }
22
+ interface NoteObject {
23
+ note: string[] | null;
24
+ length: number;
25
+ level: number;
26
+ }
27
+ interface ArpParams {
28
+ count: number;
29
+ order?: string;
30
+ chords: string | string[][];
31
+ }
32
+ /**
33
+ * Definition of a synthesizer from `Tone.js`.
34
+ */
35
+ interface SynthParams {
36
+ /**
37
+ * The name of the synthesizer, listed in `Tone.js`.
38
+ * - Example: `'PolySynth'`.
39
+ * - See: [GitHub ~ Tone.js/Tone/instrument](https://github.com/Tonejs/Tone.js/tree/dev/Tone/instrument)
40
+ */
41
+ synth: string;
42
+ /**
43
+ * Descriptive name of the preset.
44
+ */
45
+ presetName?: string;
46
+ /**
47
+ * Object with parameters for passing to `new Tone[synth](preset)`.
48
+ */
49
+ preset: Record<string, unknown>;
50
+ }
51
+ interface ClipParams {
52
+ /**
53
+ * A string or array of notes or chords names.
54
+ * - Default: `[ 'C4' ]`
55
+ * - Example: `'C4 D4 C4 D#4 C4 D4 C4 Bb3'`
56
+ */
57
+ notes?: string | (string | string[])[];
58
+ /**
59
+ * A musical rhythm, expressed using Scribbletune's pattern language,
60
+ * which can be adapted to output MIDI files or `Tone.js` sequences.
61
+ * - Default: `'x'`
62
+ * - Contains: `x_-R[]`
63
+ * - Example: `'x_x_'`
64
+ */
65
+ pattern: string;
66
+ /**
67
+ * Randomize the order of the `notes` set in the clip.
68
+ * - Default: `false`
69
+ */
70
+ shuffle?: boolean;
71
+ /**
72
+ * Whether to apply arpeggiation.
73
+ * - Default: `false`
74
+ */
75
+ arpegiate?: boolean;
76
+ /**
77
+ * Sub-division — each `x` is a quarter note by default.
78
+ * - Default: `'4n'`
79
+ * - Example: `'1m'`
80
+ * - See: [Tone.js wiki ~ Time](https://github.com/Tonejs/Tone.js/wiki/Time#notation)
81
+ */
82
+ subdiv?: string;
83
+ /**
84
+ * Align start of clip playing to specific time grid.
85
+ * - Default: `'1m'`
86
+ * - Example: `'4m'` will align the clip to every 4 measures
87
+ */
88
+ align?: string;
89
+ /**
90
+ * Offset start of clip playing from the time grid defined by `align` parameter.
91
+ * - Default: `'0'`
92
+ * - Example: `'0.75m'` will offset the clip to start at 3rd beat of 4:4 measure
93
+ */
94
+ alignOffset?: string;
95
+ /**
96
+ * The default MIDI amplitube/ level/ volume of a note.
97
+ * Used as the upper bound for accents and sizzles (where the lower bound is `accentLow`).
98
+ * - Default: `100`
99
+ * - Example: `127`
100
+ */
101
+ amp?: number;
102
+ /**
103
+ * Add a "sizzle" (in a manner of speaking) applied to the levels/ volumes.
104
+ * - Default: `false`
105
+ */
106
+ sizzle?: boolean | SizzleStyle;
107
+ /**
108
+ * Accentuate the specified notes in the clip, expressed using `x-` (on/off).
109
+ * - Example: `'x--x'`
110
+ */
111
+ accent?: string;
112
+ /**
113
+ * The minimum level used for accents.
114
+ * - Default: `70`
115
+ */
116
+ accentLow?: number;
117
+ /**
118
+ * The number of sizzle repetitions.
119
+ * - Default: `1`
120
+ */
121
+ sizzleReps?: number;
122
+ /**
123
+ * A string or array of random notes or chords.
124
+ * - Default: `null`
125
+ * - Example: `'C4 D4 C4 D#4 C4 D4 C4 Bb3'`
126
+ */
127
+ randomNotes?: null | string | (string | string[])[];
128
+ /**
129
+ * The duration of an individual sample that is used in a browser `clip`.
130
+ * - Example: `'32n'`, `'1m'`, `2.3`
131
+ * - See: [Tone.js wiki ~ Time](https://github.com/Tonejs/Tone.js/wiki/Time#notation)
132
+ */
133
+ dur?: string;
134
+ /**
135
+ * Durations of notes in a browser `clip` as a number of quarter notes.
136
+ * Internal usage only, please use the pattern notation (`x`,`-`,`_`) instead.
137
+ * - Example: `[1, 1, 0.5, 0.25]`
138
+ */
139
+ durations?: number[];
140
+ /**
141
+ * Boolean parameter to trigger offline rendering.
142
+ * If true, `scribbletune.clip` returns a `Tone.Player` with a buffer containing a pre-rendered sound of the sequence
143
+ * If false, it returns a `Tone.Sequence` which does live rendering.
144
+ */
145
+ offlineRendering?: boolean;
146
+ /**
147
+ * Callback function triggered when offline rendering is finished. Ignored when `offlineRendering: false`.
148
+ */
149
+ offlineRenderingCallback?: () => void;
150
+ /**
151
+ * URL of an audio sample for standalone clip usage (without Channel).
152
+ * - Example: `'https://scribbletune.com/sounds/kick.wav'`
153
+ */
154
+ sample?: string;
155
+ }
156
+ interface ChannelParams {
157
+ idx?: number | string;
158
+ name?: string;
159
+ clips?: ClipParams[];
160
+ /**
161
+ * Audio context (e.g. Tone.getContext())
162
+ */
163
+ context?: ToneAudioContext;
164
+ /**
165
+ * The default MIDI amplitube/ level/ volume of a note.
166
+ * Used as the upper bound for accents and sizzles (where the lower bound is `accentLow`).
167
+ * - Default: `100`
168
+ * - Example: `127`
169
+ */
170
+ amp?: number;
171
+ /**
172
+ * This use is depreceated: The name of a synthesizer, listed in `Tone.js`.
173
+ * - Example: `'PolySynth'`.
174
+ *
175
+ * New use going forward: SynthParams
176
+ */
177
+ synth?: string | SynthParams;
178
+ /**
179
+ * A `Tone.Instrument` instance or the name of a synthesizer, listed in `Tone.js`. Only in the browser.
180
+ * - Example: `'Synth'`
181
+ * - Example: `new Tone.Synth()`
182
+ */
183
+ instrument?: string | ToneInstrument;
184
+ /**
185
+ * The `URL` of an audio file containing an instrument sample. Supports `WAV` format.
186
+ * - Example: `'https://scribbletune.com/sounds/kick.wav'`
187
+ */
188
+ sample?: string;
189
+ /**
190
+ * A `Tone` buffer or any audio buffer.
191
+ * - See: https://tonejs.github.io/docs/13.8.25/Buffer
192
+ */
193
+ buffer?: string | ToneLoadable;
194
+ /**
195
+ * A dictionary of audio samples expressed as a `{ 'Note' : 'URI', ... }` object.
196
+ * - Example: `{ 'C3': 'https://.../piano48.wav', 'C#3': '/Path/to/piano49.wav', ... }`
197
+ */
198
+ samples?: Record<string, string>;
199
+ /**
200
+ * A `Promise` that resolves to a `Tone.Sampler`.
201
+ * - Example: `{ sampler: getSampler('korgBass') }`
202
+ * - See: https://github.com/scribbletune/sampler#sampler
203
+ */
204
+ sampler?: ToneInstrument;
205
+ /**
206
+ * A `Tone.Player` instance.
207
+ * - See: https://tonejs.github.io/docs/13.8.25/Player
208
+ */
209
+ player?: ToneInstrument;
210
+ /**
211
+ * External sound producer object / module
212
+ */
213
+ external?: ExternalOutput;
214
+ /**
215
+ * Name of an effect listed in `Tone.js` or `Tone.Effect` instance. Single value or Array.
216
+ * - Example: `'Chorus'`
217
+ * - Example: `new Tone.AutoFilter()`
218
+ * - Example: `[ 'Chorus', 'AutoFilter' ]`
219
+ */
220
+ effects?: string | ToneNode | (string | ToneNode)[];
221
+ /**
222
+ * The volume in decibels, in the range `-60` to `+12`.
223
+ * - Default: `0`
224
+ * - Example: `-18`
225
+ */
226
+ volume?: number;
227
+ /**
228
+ * Callback function triggered when a note is played.
229
+ */
230
+ eventCb?: EventFn;
231
+ /**
232
+ * Callback function triggered when a note is played.
233
+ */
234
+ playerCb?: PlayerObserverFn;
235
+ }
236
+ type ChannelPattern = {
237
+ /**
238
+ * Channel index to apply the playing pattern.
239
+ * - Example: `0`
240
+ * - Example: `'beat'`
241
+ */
242
+ channelIdx: string;
243
+ /**
244
+ * The song structure for one channel, saying which clip to play at each step.
245
+ * - Contains: `0123456789_-`
246
+ * - Example: `'0___1___----'`
247
+ */
248
+ pattern: string;
249
+ };
250
+ interface PlayParams {
251
+ /**
252
+ * An array of ChannelPattern
253
+ */
254
+ channelPatterns: ChannelPattern[];
255
+ /**
256
+ * The time duration to play each clip in the patterns. Default is 4 bars.
257
+ * - Default: `'4:0:0'`
258
+ * - Example: `'1:0:0'`
259
+ */
260
+ clipDuration?: string;
261
+ }
262
+ interface TPD {
263
+ /** Tonic */
264
+ T: string[];
265
+ /** Predominant (or subdominant) */
266
+ P: string[];
267
+ /** Dominant */
268
+ D: string[];
269
+ }
270
+
271
+ /**
272
+ *
273
+ * @param chordsOrParams a string that denotes space (comma?) separated chords to be used or an object with additional properties
274
+ * By default, if this is a string, the count of notes generated is 8 and the order is ascending.
275
+ * For instance arp('CM FM') will result in an array of notes [C4, E4, G4, F4, A4, C4, C5, E5]
276
+ * You can even provide Params as an object.
277
+ * For e.g. arp({count: 8, order: '10325476', chords: 'FM_4 Gm7b5_4 AbM_4 Bbm_4 Cm_5 DbM_5 EbM_5})
278
+ */
279
+ declare const arp: (chordsOrParams: string | ArpParams) => string[];
280
+
281
+ /**
282
+ * Generate an array of note objects from clip parameters (for MIDI export).
283
+ * Applies the pattern to notes, then optionally adds sizzle and accent dynamics.
284
+ */
285
+ declare const clip: (params: ClipParams) => NoteObject[];
286
+
287
+ /**
288
+ * Take an array of note objects to generate a MIDI file in the same location as this method is called
289
+ * @param {NoteObject[]} notes Notes are in the format: {note: ['c3'], level: 127, length: 64}
290
+ * @param {String | null} fileName If a filename is not provided, then `music.mid` is used by default
291
+ * If `null` is passed for `fileName`, bytes are returned instead of creating a file
292
+ * If this method is called from a browser then it will return a HTML link that you can append in your page
293
+ * This link will enable the generated MIDI as a downloadable file.
294
+ * @param {Number | null} bpm If a value is provided, the generated midi file will be set to this bpm value.
295
+ */
296
+ declare const midi: (notes: NoteObject[], fileName?: string | null, bpm?: number) => string | HTMLAnchorElement | undefined;
297
+
298
+ /**
299
+ * Get the chords that go with a given scale/mode
300
+ * This is useful only in case you want to check what chords work with a scale/mode
301
+ * so that you can come up with chord progressions
302
+ * @param {String} mode e.g. major
303
+ * @return {Array} e.g.['I', 'ii', 'iii', 'IV', 'V', 'vi', 'vii°']
304
+ */
305
+ declare const getChordDegrees: (mode: string) => string[];
306
+ /**
307
+ * Take the specified scale and degrees and return the chord names for them
308
+ * These can be used as the value for the `notes` param of the `clip` method
309
+ * @param {String} noteOctaveScale e.g. 'C4 major'
310
+ * @param {String} chordDegress e.g. 'I IV V IV'
311
+ * @return {String} e.g. 'CM FM GM FM'
312
+ */
313
+ declare const getChordsByProgression: (noteOctaveScale: string, chordDegress: string) => string;
314
+ /**
315
+ * Generate a chord progression based on basic music theory
316
+ * where we follow tonic to optionally predominant and then dominant
317
+ * and then randomly to predominant and continue this till we reach `count`
318
+ * @param scaleType e.g. M (for major chord progression), m (for minor chord progression)
319
+ * @param count e.g. 4
320
+ */
321
+ declare const progression: (scaleType: ProgressionScale, count?: number) => string[];
322
+
323
+ export { type ArpParams, type ChannelParams, type ChannelPattern, type ClipParams, type EventFn, type NVP, type NoteObject, type PatternElement, type PlayParams, type PlayerObserverFn, type ProgressionScale, type SeqFn, type SizzleStyle, type SynthParams, type TPD, arp, clip, getChordDegrees, getChordsByProgression, midi, progression };