nwhetsell / csound-api Goto Github PK
View Code? Open in Web Editor NEWNode.js bindings to Csound’s API
Home Page: https://www.npmjs.com/package/csound-api
License: MIT License
Node.js bindings to Csound’s API
Home Page: https://www.npmjs.com/package/csound-api
License: MIT License
Hello,
I'm getting an error when trying npm install csound-api
. Here are some details:
brew install boost
The error I get looks like this:
npm ERR! code 1
npm ERR! path /Users/hallenj/Documents/csound/node/node_modules/csound-api
npm ERR! command failed
npm ERR! command sh -c /var/folders/lr/q0m4k0hx34q16lqv0x138d980000gn/T/install659759855.sh
...
../src/csound-api.cc:1:10: fatal error: 'boost/lockfree/queue.hpp' file not found
npm ERR! #include <boost/lockfree/queue.hpp>
When I run g++ -E -x c++ - -v < /dev/null
to see the directories GCC searches I get this:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
However, /usr/local/include
is empty. When I run brew list boost
I see:
/opt/homebrew/Cellar/boost/1.79.0_1/include/boost/
/opt/homebrew/Cellar/boost/1.79.0_1/lib/libboost_atomic-mt.dylib
etc
I'm guessing there needs to be some connection between the GCC search paths and the Boost libraries. Do you have any suggestions for what I might try next? I'm super excited to work with your csound-api
!
Thanks!
Jason
hi,
if I run the PerformAsync example I get the following error.
can anyone help me resolving this problem?
virtual_keyboard real time MIDI plugin for Csound
0dBFS level = 32768.0
Csound version 6.04 (double samples) 2016-02-21
libsndfile-1.0.25
realtime mode enabled
instr SawtoothSweep uses instrument number 1
rtaudio: ALSA module enabled
rtmidi: ALSA Raw MIDI module enabled
--Csound version 6.04 (double samples) 2016-02-21
graphics suppressed, ascii substituted
0dBFS level = 1.0
orch now loaded
audio buffered in 512 sample-frame blocks
ALSA: -b 512 not allowed on this device; using 341 instead
ALSA output: total buffer size: 1024, period size: 341
writing 512 sample blks of 64-bit floats to dac
SECTION 1:
**node: symbol lookup error: /home/olimex/guitarFX/node_modules/csound-api/build/Release/csound-api.node: undefined symbol: __atomic_load_16**
bests.
I am trying to upgrade the current version of QTCsound on a MacBook Pro (recently upgraded to Catalina 10.15.1) so I installed Homebrew before installing Boost and Csound in Terminal following step one, i.e. brew install boost csound. When I try to install the package in step 2 npm install csound-api the following error message appears in Terminal
> [email protected] install /Users/gs/node_modules/csound-api
> node-gyp rebuild
CXX(target) Release/obj.target/csound-api/src/csound-api.o
../src/csound-api.cc:3:10: fatal error: 'csound/cwindow.h' file not found
stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
Here are the first ten lines of the log /Users/gs/.npm/_logs/2019-12-10T07_55_15_791Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/usr/local/Cellar/node/12.5.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'csound-api'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose config Skipping project config: /Users/gs/.npmrc. (matches userconfig)
Help ! What should I do ?
I'm playing around with some nodejs cli tool hacking. I'm looking to create csound instances for specific tasks like csound.NewOpcodeList
, but on each create I get the initial csound logs
0dBFS level = 32768.0
--Csound version 6.11 (double samples) Jan 1 1970
[commit: none]
libsndfile-1.0.28
But csound.SetMessageCallback
can only take effect after csound instance is created. This is certainly csound related. But maybe in the nan bindings, there could be a env variable or global variable, or function that doesn't take csound instance as parameter, that could signal, not to print these messages?
I've tried supressing this by tapping into the process.stdout.write, but this is probably on another thread so little I can do. I could execute this in a thread worker, but that's still experimental technology.
Hi Nate,
I'm testing out running csound-api
with Electron. Here's the package.json file:
{
"name": "mell-fark",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"devDependencies": {
"electron": "^20.0.1"
},
"dependencies": {
"csound-api": "^0.10.20"
}
}
main.js
is your "Run Csound asynchronously, and stop Csound in mid-performance" example. I've run npm install
which successfully installs csound-api
and Electron.
First of all, when I run node main.js
everything works well. However, when I try to run main.js
through Electron with
npm start
I get this error message:
Error: The module '/Users/hallenj/Documents/csound/node/node_modules/csound-api/build/Release/csound-api.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 108. This version of Node.js requires
NODE_MODULE_VERSION 107. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1812)
at Module._extensions..node (node:internal/modules/cjs/loader:1205:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1812)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at c._load (node:electron/js2c/asar_bundle:5:13343)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/hallenj/Documents/csound/node/main.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
I've tried running npm rebuild
and npm install
and following suggestions in StackExchange for similar error messages, but nothing is fixing this. Do you have any suggestions or at least an explanation of what is going on?
Thanks for any help you can give,
Jason
If an asynchronous performance is playing, and a SIGINT (Ctrl + C) is sent, CSound correctly shows that the interrupt was caught, stops the performance and begins tidying up.
However, this process doesn't appear to complete. It hangs the node process until a second SIGINT is sent, CSound catches it again and then actually terminates.
A workaround is to catch the SIGINT signal and manually stop the playback, but isn't ideal.
Example code
const csound = require('csound-api');
const Csound = csound.Create();
csound.SetOption(Csound, '--output=dac');
csound.CompileOrc(Csound, `
0dbfs = 1
giFunctionTableID ftgen 0, 0, 16384, 10, 1
instr A440
outc oscili(0.5 * 0dbfs, 440, giFunctionTableID)
endin
`);
csound.ReadScore(Csound, `
i "A440" 0 10
e
`);
if (csound.Start(Csound) === csound.SUCCESS) {
csound.PerformAsync(Csound, (result) => {
if(result > 0) {
console.log('We reached the end of the score');
} else {
console.log('Csound stopped');
}
csound.Destroy(Csound);
});
}
/* Uncomment the below to show expected behaviour */
// process.on('SIGINT', function() {
// csound.Stop(Csound);
// });
As I'm running this API on clojurescript I'm not sure if a reproduceable code makes much sense. But no matter how I try, restarting csound instance is impossible. The nodejs repl becomes unresponsive after stopping, resetting, destroyng ore cleanup-ing a csound instance. Maybe a special function to stop PerformAsync would make sense as I'm assumeing that in the c# code it's a pointer to a concurrent function? (where some signal within that function would stop the concurrent loop).
Consider the dramatic difference in accuracy between these two code snippets, varying in ksmps value.
const csound = require('csound-api');
const Csound = csound.Create();
csound.SetOption(Csound, '--output=dac');
csound.CompileOrc(Csound, `
0dbfs = 1
ksmps = 1
alwayson 1
instr 1
asig poscil 80, 0.2
asig2 poscil 162, 0.2
aenv expon 1, 0.1, 0.0001
outc (asig2+asig)*aenv
endin
`);
setInterval(function() {csound.InputMessage(Csound, `i 1 0 1`)},100);
if (csound.Start(Csound) === csound.SUCCESS) {
csound.PerformAsync(Csound, () => csound.Destroy(Csound));
setTimeout(() => csound.Stop(Csound), 10000);
}
const csound = require('csound-api');
const Csound = csound.Create();
csound.SetOption(Csound, '--output=dac');
csound.CompileOrc(Csound, `
0dbfs = 1
ksmps = 64
alwayson 1
instr 1
asig poscil 80, 0.2
asig2 poscil 162, 0.2
aenv expon 1, 0.1, 0.0001
outc (asig2+asig)*aenv
endin
`);
setInterval(function() {csound.InputMessage(Csound, `i 1 0 1`)},100);
if (csound.Start(Csound) === csound.SUCCESS) {
csound.PerformAsync(Csound, () => csound.Destroy(Csound));
setTimeout(() => csound.Stop(Csound), 10000);
}
This is an oversimplification of the problem Im having atm, that an increase in ksmps throws all event accuracy out the window (but the workload on each instrument on the other hand could potentially be solved with higher ksmps). The rate of 64ksmps is 44100/64x a second, find it unlikely that such a rate that is still very fast, could account for all this delay. And I also notice that other processes in nodejs seem to go on hold while the .InputMessage is being performed, making me suspect that this is not an async action?
Two seperated things, must add that I'm a nodejs noob so these may end up just being questions.
Firstly, as I'm running on a self-hosted cljs-nodejs environment unlike before, I now get this error
Error: The module '/home/hlolli/csound/node-panaeolus/node_modules/csound-api/build/Release/csound-api.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 51. Please try re-compiling or re-installing
I guess I could either recompile this module or version bump the project?
Second thing is again related to the .PerformAsync function. In the spirit of the csound-api examples, it would be great to deliver a function pointer like you already provide as the second parameter to .PerformAsync, which as I see gets called at the end of performance. But also a function pointer that gets called on every control rate (ex. a .PerformKsmps recursion), that way one can do js callback from the csound thread. Maybe there's a more clever way around this, but I can't think of anything better than setting super fast .setInterval to measure how much time has passed in csound.
This is the error message I'm getting
> require("csound-api")
Error: /home/hlolli/Music/erkitid_2018/node_modules/csound-api/build/Release/csound-api.node: undefined symbol: _ZN2v814ObjectTemplate11SetAccessorENS_5LocalINS_4NameEEEPFvS3_RKNS_20PropertyCallbackInfoINS_5ValueEEEEPFvS3_NS1_IS5_EERKNS4_IvEEESB_NS_13AccessControlENS_17PropertyAttributeENS1_INS_17AccessorSignatureEEENS_14SideEffectTypeE
at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
I'm on NixOs whith node version 10.7.0, boost 1.66.0 and csound 6.11.0.
This could be nixOs related issue. Maybe I try this with node10 on other OS/distro to confirm.
Hi Nate!
I've got an issue for you, though it might be a Node issue rather than csound-api
. I'm on an Mac with an M1 processor.
When I call .GetControlChannel()
when running .PerformAsync()
in Node I'm getting repeated values from Csound. I would expect the values to be changing each time the method is called. It's like there's some kind of throttling that is limiting the output of .GetControlChannel()
. I'm hoping to find out what the underlying issue is.
const csound = require('csound-api')
const Csound = csound.Create()
csound.SetOption(Csound, '--output=dac')
csound.CompileOrc(Csound, `
0dbfs = 1
instr 1
kenv line 0, p3, 1
asig oscil kenv, 220
ktrig metro 20
kmeter max_k asig, ktrig, 1
printk2 kmeter
chnset kmeter, "meter"
endin
`)
csound.ReadScore(Csound, `
i 1 0 1
i 1 1 1
i 1 2 1
e
`)
if (csound.Start(Csound) === csound.SUCCESS) {
csound.PerformAsync(Csound, () => csound.Destroy(Csound))
}
function readCsoundValues(){
let amplitude = csound.GetControlChannel(Csound, "meter")
console.log(amplitude)
setTimeout(readCsoundValues, 50)
}
readCsoundValues()
Here's a quick overview of what's happening.
An oscillator outputs an oscillator signal (asig
) with an amplitude that ramps up from 0 to 1. A metronome triggers max_k
to read the amplitude of asig
20 times a second. Csound then sends the amplitude value out to the "meter
" channel. printk2
shows that the amplitude increases incrementally for each k-cycle as expected. Here's the output.
i1 0.00000
i1 0.04875
i1 0.09887
i1 0.14875
i1 0.19886
i1 0.24875
i1 0.29886
i1 0.34875
i1 0.39886
i1 0.44875
i1 0.49886
i1 0.54875
i1 0.59886
i1 0.64874
i1 0.69886
i1 0.74874
i1 0.79885
i1 0.84874
i1 0.89885
i1 0.94874
A function calls .GetControlChannel()
20 times per second and prints the output. I would expect the output to similarly increase each time the function is called, but it repeats the values twice. Here's the output.
0.09886562427796818
0.09886562427796818
0.19886475080527538
0.19886475080527538
0.29886355394942954
0.29886355394942954
0.34874973139167503
0.44874884162817624
0.44874884162817624
0.5487470237683278
0.5487470237683278
0.6487447722417382
0.6487447722417382
0.7487435295149353
0.7487435295149353
0.848740601660029
0.9487391603915499
0.9487391603915499
I tried to increase the resolution on both sides to fix the problem, but it didn't change anything. For example, I increased the Csound metronome to send the amplitude 100 times per second, but it didn't change the output in Node. When I increased the .GetControlChannel()
calls in Node to 100 times per second I just got more repeated values like this.
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.09886562427796818
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.19886475080527538
0.29886355394942954
0.29886355394942954
0.29886355394942954
etc
In fact, Node only ever outputs 10 to 11 different values per second no matter how many times the function is called per second, as though it is throttled to reading .GetControlChannel()
around 10 times per second. When I time how long it takes Node to get a result from .GetControlChannel()
I get an average of about 0.015ms, which seems fast enough to be called 100 times per second.
I understand that the timing between .GetControlChannel()
calls in Node won't be consistent, but timing doesn't matter as much as resolution in this case.
Do you know if there is some kind of throttling happening within csound-api
that is limiting the .GetControlChannel()
to sending 10 times per second? Otherwise, the problem might be within Node. I'm admittedly new to Node, so I could also be misunderstanding how it works.
Thanks as always for your guidance!
Jason
When installing on debian linux Jessie
get the following error.
[email protected] install /home/csound/node_modules/csound-apinode-gyp rebuild
make: Entering directory '/home/csound/node_modules/csound-api/build'
CXX(target) Release/obj.target/csound-api/src/csound-api.o
../src/csound-api.cpp:2:21: fatal error: csdebug.h: No such file or directory
#include <csdebug.h>
^
compilation terminated.
csound-api.target.mk:92: recipe for target 'Release/obj.target/csound-api/src/csound-api.o' failed
make: *** [Release/obj.target/csound-api/src/csound-api.o] Error 1
make: Leaving directory '/home/csound/node_modules/csound-api/build'
I'm on a Raspberry Pi 3 (Wheezy) and following your steps. (Except I do not execute the command to install csound, since that I have that already.) I do execute the ln
command, though.
After that, when I do:
npm install csound-api
I get the following error:
> [email protected] install /home/pi/node_modules/csound-api
> node-gyp rebuild
make: Entering directory '/home/pi/node_modules/csound-api/build'
CXX(target) Release/obj.target/csound-api/src/csound-api.o
../src/csound-api.cc:1:36: fatal error: boost/lockfree/queue.hpp: No such file or directory
#include <boost/lockfree/queue.hpp>
It seems a problem with boost?
When I install boost again, it says it is already the latest version..
> [email protected] install /Users/martin/Private/projects/node-kissfft/node_modules/csound-api
> node-gyp rebuild
CXX(target) Release/obj.target/csound-api/src/csound-api.o
../src/csound-api.cpp:1:10: fatal error: 'boost/lockfree/queue.hpp' file not found
#include <boost/lockfree/queue.hpp>
^
1 error generated.
make: *** [Release/obj.target/csound-api/src/csound-api.o] Error 1
Feature request for adding CompileOrc and EvalCode to csoundEventType, like was done with readScore and inputMessage. This would prevent csound from waiting when those events are fired, enabling realtime instrument changes, these delays become more extreme with higher ksmps value. Like before, this is only a problem on linux.
The following example on linux is very modest, compared to the delay I experience on my live-coding environment.
const csound = require('bindings')('csound-api.node');
const Csound = csound.Create();
csound.SetOption(Csound, '--output=dac');
csound.CompileOrc(Csound, `
0dbfs = 1
//ksmps = 128
ksmps = 1
alwayson 1
instr 1
asig poscil 80, 0.2
asig2 poscil 162, 0.2
aenv expon 1, 0.1, 0.0001
outc (asig2+asig)*aenv
endin
`);
var cnt = 0;
setInterval(function() {csound.InputMessage(Csound, `i 1 0 1`);
cnt += 1;
if ((cnt % 10) == 0 ) {csound.CompileOrc(Csound,
`instr 1
asig poscil ${Math.random()*60+60}, 0.2
asig2 poscil ${Math.random()*120+60}, 0.2
aenv expon 1, 0.1, 0.0001
outc (asig2+asig)*aenv
endin`
)};},100);
if (csound.Start(Csound) === csound.SUCCESS) {
csound.PerformAsync(Csound, () => csound.Destroy(Csound));
setTimeout(() => csound.Stop(Csound), 20000);
}
It would be handy for csound-api to work from a global install npm install -g csound-api. Currently if installed globally when trying to require I get the error:
Error: Cannot find module 'csound-api'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at repl:1:16
at ContextifyScript.Script.runInThisContext (vm.js:23:33)
at REPLServer.defaultEval (repl.js:339:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:536:10)
Hi, this is the message I get when trying to install. Any suggestions on how to fix it?
Thanks
Pouring csound-6.12.2_2.high_sierra.bottle.tar.gz
Warning: csound dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
Error: The brew link
step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/atsa
Target /usr/local/bin/atsa
already exists. You may want to remove it:
rm '/usr/local/bin/atsa'
To force the link and overwrite all conflicting files:
brew link --overwrite csound
To list all files that would be deleted:
brew link --overwrite --dry-run csound
Possible conflicting files are:
/usr/local/bin/atsa
/usr/local/bin/cs
/usr/local/bin/csanalyze
/usr/local/bin/csb64enc
/usr/local/bin/csbeats
/usr/local/bin/csdebugger
/usr/local/bin/csound
/usr/local/bin/cvanal
/usr/local/bin/dnoise
/usr/local/bin/envext
/usr/local/bin/extract
/usr/local/bin/extractor
/usr/local/bin/het_export
/usr/local/bin/het_import
/usr/local/bin/hetro
/usr/local/bin/lpanal
/usr/local/bin/lpc_export
/usr/local/bin/lpc_import
/usr/local/bin/makecsd
/usr/local/bin/mixer
/usr/local/bin/pv_export
/usr/local/bin/pv_import
/usr/local/bin/pvanal
/usr/local/bin/pvlook
/usr/local/bin/scale
/usr/local/bin/scot
/usr/local/bin/scsort
/usr/local/bin/sdif2ad
/usr/local/bin/sndinfo
/usr/local/bin/src_conv
/usr/local/bin/srconv
/usr/local/include/csound -> /Library/Frameworks/CsoundLib64.framework/Headers
/usr/local/lib/libcsnd6.6.0.dylib -> /Library/Frameworks/CsoundLib64.framework/Versions/6.0/libcsnd6.6.0.dylib
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.