Last active
July 15, 2016 20:22
-
-
Save johnty/5de18df3144235e62e4b89d2315912c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // instructions: | |
| // 1.) install node.js and npm | |
| // 2.) put this file in a folder | |
| // 3.) go to this folder in terminal, and install ffi and ref using 'npm install ...' | |
| // 4.) execute by typing `node node-ffi-mapper.js` | |
| // | |
| // note: refers explicitly to libmapper-0.2.dylib so make sure it is on the path! | |
| var ref = require('ref'); | |
| var ffi = require('ffi'); | |
| var go_on = true; | |
| var mapper = ref.types.void; | |
| var mapperPtr = ref.refType(mapper); | |
| var mapperDevPtr = ref.refType(mapperPtr); | |
| var mapperSigPtr = ref.refType(mapperPtr); | |
| var mapperVoidPtr = ref.refType('void'); | |
| var libmapper = ffi.Library('libmapper-0.2', { | |
| 'mdev_new': [mapperDevPtr, ['string', 'int', 'int']], | |
| 'mdev_poll': ['int', [mapperDevPtr, 'int']], | |
| 'mdev_add_output': [mapperSigPtr, [mapperDevPtr, 'string', | |
| 'int', 'char', 'string', | |
| mapperVoidPtr, mapperVoidPtr]], | |
| 'msig_update_int' : ['void', [mapperSigPtr, 'int']] | |
| }); | |
| //var devPtrPtr = ref.alloc(mapperDevPtr); | |
| console.log("init device..."); | |
| var devPtrPtr = libmapper.mdev_new("device", 0, 0); | |
| if (devPtrPtr.isNull()) | |
| console.log("Err!"); | |
| else | |
| console.log("created device"); | |
| var devPtr = devPtrPtr.deref(); | |
| console.log("adding output signal"); | |
| var minPtrPtr = ref.alloc('void'); | |
| var maxPtrPtr = ref.alloc('void'); | |
| var devSigPtr = libmapper.mdev_add_output(devPtrPtr, "test_sig", 1, 'i', "hz", minPtrPtr, maxPtrPtr); | |
| var i = 0; | |
| while (go_on) { | |
| console.log("update/poll..."); | |
| libmapper.msig_update_int(devSigPtr, i++); | |
| libmapper.mdev_poll(devPtrPtr, 500); | |
| } | |
| console.log("ok"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment