Api
interface Api {
newProject(name?: string): Project
hasProject(): Promise<boolean>
getProject(): Promise<Project>
showInfo(headline: string, message: string): Promise<void>
showDialog<F extends Record<string, DialogField>>(dialog: DialogSpec<F>): Promise<Nullable<DialogValues<F>>>
addSample(data: AudioData, name: string): Promise<Sample>
listSamples(): Promise<readonly Sample[]>
saveFile(data: ArrayBuffer | ArrayBufferView<ArrayBufferLike>, fileName: string, mimeType?: string): Promise<void>
}The global openDAW object, entry point of every script
Methods
newProject(name?: string): Project
Create a new empty project
Parameters
name(string, optional)
Returns
Example
const project = openDAW.newProject("Hello")
project.bpm = 120
project.openInStudio()hasProject(): Promise<boolean>
Whether a project is open in the studio
Returns
Promise<boolean>
getProject(): Promise<Project>
Load the project currently open in the studio for modification. Call Project.openInStudio to apply. Throws if none is open
Returns
Example
const project = await openDAW.getProject()
project.audioUnits.forEach(unit => unit.mute = false)
project.openInStudio()showInfo(headline: string, message: string): Promise<void>
Show an info dialog in the studio and wait until it is closed
Parameters
headline(string)message(string)
Returns
Promise<void>
showDialog<
F extends Record<string, DialogField>,
>(
dialog: DialogSpec<F>,
): Promise<Nullable<DialogValues<F>>>
Ask the user for values in a dialog. Resolves with the values, or with null when the dialog was cancelled
Type Parameters
FextendsRecord<string, DialogField>
Parameters
dialog(DialogSpec<F>)
Returns
Promise<Nullable<DialogValues<F>>>
Example
const values = await openDAW.showDialog({
headline: "New Pad",
okText: "Create",
fields: {
name: {type: "text", label: "Name", value: "Pad"},
voices: {type: "number", label: "Voices", value: 32, min: 1, max: 64, step: 1},
sound: {type: "section", label: "Sound"},
bandwidth: {type: "slider", label: "Bandwidth", value: 45, min: 1, max: 200, mapping: "exp", unit: "ct"},
zone: {type: "dropdown", label: "Semitones per zone", value: 3,
options: [{label: "One", value: 1}, {label: "Three", value: 3}, {label: "Six", value: 6}]},
randomStart: {type: "checkbox", label: "Random start", value: true}
}
})
if (values === null) {return}
const project = openDAW.newProject(values.name)- See:
addSample(data: AudioData, name: string): Promise<Sample>
Create a sample in the studio from raw audio data
Parameters
data(AudioData)name(string)
Returns
Example
const audio = AudioData.create(sampleRate, sampleRate, 1)
audio.frames[0].forEach((_, index) => audio.frames[0][index] = Math.sin(index * 440 / sampleRate * Math.PI * 2) * 0.5)
const sample = await openDAW.addSample(audio, "Sine")listSamples(): Promise<readonly Sample[]>
All samples available in the studio (stock and user samples)
Returns
saveFile(
data: ArrayBuffer | ArrayBufferView<ArrayBufferLike>,
fileName: string,
mimeType?: string,
): Promise<void>
Offer a file for download. The studio asks for confirmation, then shows the save dialog
Parameters
data(ArrayBuffer | ArrayBufferView<ArrayBufferLike>) — File contentfileName(string) — Suggested name including extensionmimeType(string, optional) — Content type (default "application/octet-stream")
Returns
Promise<void>
Example
const audio = await project.mixdown()
await openDAW.saveFile(WavFile.encodeFloats(audio), "mixdown.wav", "audio/wav")