Api

interface Api { newProject(name?: string): Project hasProject(): Promise<boolean> getProject(): Promise<Project> showInfo(headline: string, message: string): Promise<void> 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>

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