csound-api
Version:
Node.js bindings to Csound’s API
46 lines (42 loc) • 1.51 kB
JavaScript
const ansi = require('ansi-styles');
const csound = require('bindings')('csound-api.node');
const textColors = {
[] : ansi.black,
[] : ansi.red,
[] : ansi.green,
[] : ansi.yellow,
[] : ansi.blue,
[] : ansi.magenta,
[] : ansi.cyan,
[] : ansi.gray
};
const backgroundColors = {
[] : ansi.bgBlack,
[] : ansi.bgRed,
[] : ansi.bgGreen,
[] : ansi.bgYellow,
[] : ansi.bgBlue,
[] : ansi.bgMagenta,
[] : ansi.bgCyan,
[] : ansi.bgWhite
};
const Csound = csound.Create();
csound.SetMessageCallback(Csound, (attributes, string) => {
let color = textColors[attributes & csound.MSG_FG_COLOR_MASK];
if (color)
string = color.open + string + color.close;
if (attributes & csound.MSG_FG_BOLD)
string = ansi.bold.open + string + ansi.bold.close;
if (attributes & csound.MSG_FG_UNDERLINE)
string = ansi.underline.open + string + ansi.underline.close;
color = backgroundColors[attributes & csound.MSG_BG_COLOR_MASK];
if (color)
string = color.open + string + color.close;
console.log(string);
});
csound.MessageS(
Csound,
csound.MSG_FG_YELLOW | csound.MSG_FG_UNDERLINE | csound.MSG_BG_BLUE,
'Hail!'
);
csound.Destroy(Csound);