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

CODE
const project = openDAW.newProject("Hello")
project.bpm = 120
project.openInStudio()

hasProject(): Promise<boolean>

async

Whether a project is open in the studio

Returns

  • Promise<boolean>

getProject(): Promise<Project>

async

Load the project currently open in the studio for modification. Call Project.openInStudio to apply. Throws if none is open

Returns

Example

CODE
const project = await openDAW.getProject()
project.audioUnits.forEach(unit => unit.mute = false)
project.openInStudio()

showInfo(headline: string, message: string): Promise<void>

async

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>>>

async

Ask the user for values in a dialog. Resolves with the values, or with null when the dialog was cancelled

Type Parameters

Parameters

Returns

Example

CODE
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)

addSample(data: AudioData, name: string): Promise<Sample>

async

Create a sample in the studio from raw audio data

Parameters

  • data (AudioData)
  • name (string)

Returns

Example

CODE
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[]>

async

All samples available in the studio (stock and user samples)

Returns

saveFile( data: ArrayBuffer | ArrayBufferView<ArrayBufferLike>, fileName: string, mimeType?: string, ): Promise<void>

async

Offer a file for download. The studio asks for confirmation, then shows the save dialog

Parameters

  • data (ArrayBuffer | ArrayBufferView<ArrayBufferLike>) — File content
  • fileName (string) — Suggested name including extension
  • mimeType (string, optional) — Content type (default "application/octet-stream")

Returns

  • Promise<void>

Example

CODE
const audio = await project.mixdown()
await openDAW.saveFile(WavFile.encodeFloats(audio), "mixdown.wav", "audio/wav")