Variables Class

Provides access to Cantabile's internal variables by allowing a pattern string to be expanded into a final display string.

Access this object via the Cantabile#variables property.

class Variables extends EndPoint {
    resolve(pattern: string): Promise<string>;
    watch(pattern: string, callback?: PatternWatcherCallback): PatternWatcher;
}

#Methods

#resolve()

Resolves a variable pattern string into a final display string

resolve(pattern: string): Promise<string>;
  • pattern The string variable pattern to resolve

Example

console.log(await C.variables.resolve("Song: $(SongTitle)"));

Example

C.variables.resolve("Song: $(SongTitle)").then(r => console.log(r)));

#watch()

Starts watching a pattern string for changes

watch(pattern: string, callback?: PatternWatcherCallback): PatternWatcher;
  • pattern The string pattern to watch

  • callback Optional callback function to be called when the resolved display string changes.

Example

// Watch a string pattern using a callback function
C.variables.watch("Song: $(SongTitle)", function(resolved) {
    console.log(resolved);
})

Example

// Using the PatternWatcher class and events:
let watcher = C.variables.watch("Song: $(SongTitle)");
watcher.on('changed', function(resolved) {
    console.log(resolved);
});

/// later, stop listening
watcher.unwatch();