Skip to content

Commit

Permalink
[v0.5.11] bpm and steps in the UI now matches current transport state…
Browse files Browse the repository at this point in the history
… at all times
  • Loading branch information
nnirror committed Jan 7, 2023
1 parent 11114c6 commit c856e7a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Below the text editor, there are several UI elements which control the Facet ser

- Server connection status indicator (green = online; red = offline)
- CPU% indicator
- Slider for setting the BPM of the global transport (_note_: when the `.bpm()` operation runs, this value is overridden)
- Slider for setting the number of steps in a whole note (_note_: when the `.steps()` operation runs, this value is overridden)
- Slider for setting the BPM of the global transport (_note_: when the `.bpm()` operation runs, this value is updated automatically)
- Slider for setting the number of steps in a whole note (_note_: when the `.steps()` operation runs, this value is updated automatically)
- MIDI output selector / refresh button
- ▶ = start playback
- ■ = stop playback
Expand Down
8 changes: 8 additions & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ const osc = new OSC({ plugin: new OSC.WebsocketClientPlugin() });
osc.open();
checkStatus();

osc.on('/bpm', message => {
$('#bpm').val(`${message.args[0]}`);
});

osc.on('/steps', message => {
$('#steps').val(`${message.args[0]}`);
});

osc.on('/cpu', message => {
let cpu_percent = parseFloat(message.args[0]).toFixed(2).substring(0,4);
$('#cpu').html(cpu_percent + '% cpu');
Expand Down
6 changes: 6 additions & 0 deletions js/pattern_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ app.post('/stop', (req, res) => {
res.sendStatus(200);
});

app.post('/meta', (req, res) => {
osc_package.send(new OSCPACKAGE.Message(`/bpm`, req.body.bpm));
osc_package.send(new OSCPACKAGE.Message(`/steps`, req.body.steps));
res.sendStatus(200);
});

app.get('/update', (req, res) => {
for (const [fp_name, code] of Object.entries(reruns)) {
module.exports.run(code);
Expand Down
20 changes: 20 additions & 0 deletions js/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ let meta_data = {
bpm: [90],
steps: [16]
};
let prev_bpm;
let prev_steps;
let cross_platform_slash = process.platform == 'win32' ? '\\' : '/';
let cross_platform_play_command = process.platform == 'win32' ? 'sox' : 'play';
let cross_platform_sox_config = process.platform == 'win32' ? '-t waveaudio' : '';
Expand Down Expand Up @@ -153,6 +155,10 @@ function tick() {
if ( steps > max_steps_for_bpm ) {
steps = max_steps_for_bpm;
}
if ( (bpm != prev_bpm) || (steps != prev_steps) ) {
reportTransportMetaData(bpm,steps);
}

handleBpmChange();
let count_wav_files_played_this_step = 0;
// begin looping through all facet patterns, looking for wavs/notes/CCs to play
Expand Down Expand Up @@ -286,6 +292,8 @@ function tick() {
else {
current_step++;
}
prev_bpm = bpm;
prev_steps = steps;
}
}

Expand Down Expand Up @@ -342,6 +350,18 @@ function handleBpmChange() {
}
}

function reportTransportMetaData() {
axios.post('http://localhost:1123/meta',
{
bpm: JSON.stringify(bpm),
steps: JSON.stringify(steps)
}
)
.catch(function (error) {
console.log(`error posting metadata to pattern server: ${error}`);
});
}

function scalePatternToSteps(pattern,steps) {
// scale note pattern onto a bar of length _steps_.
if (pattern.length < steps ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facet",
"version": "0.5.10",
"version": "0.5.11",
"description": "Facet is a live coding system for algorithmic music",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit c856e7a

Please sign in to comment.