mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 05:38:34 +00:00
its working
This commit is contained in:
parent
60e600c381
commit
62e3774ff7
43
packages/desktopbridge/oscbridge.mjs
Normal file
43
packages/desktopbridge/oscbridge.mjs
Normal file
@ -0,0 +1,43 @@
|
||||
import { logger, parseNumeral, Pattern } from '@strudel.cycles/core';
|
||||
import { Invoke } from './utils.mjs';
|
||||
|
||||
Pattern.prototype.osc = function () {
|
||||
return this.onTrigger(async (time, hap, currentTime, cps = 1) => {
|
||||
hap.ensureObjectValue();
|
||||
const cycle = hap.wholeOrPart().begin.valueOf();
|
||||
const delta = hap.duration.valueOf();
|
||||
const controls = Object.assign({}, { cps, cycle, delta }, hap.value);
|
||||
// make sure n and note are numbers
|
||||
controls.n && (controls.n = parseNumeral(controls.n));
|
||||
controls.note && (controls.note = parseNumeral(controls.note));
|
||||
|
||||
const messagesfromjs = [];
|
||||
const params = [];
|
||||
const offset = Math.round((time - currentTime) * 1000 - 48);
|
||||
|
||||
Object.keys(controls).forEach((key) => {
|
||||
const val = controls[key];
|
||||
const value = typeof val === 'number' ? val.toString() : val;
|
||||
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
params.push({
|
||||
name: key,
|
||||
value,
|
||||
valueisnumber: typeof val === 'number',
|
||||
});
|
||||
});
|
||||
|
||||
if (params.length) {
|
||||
messagesfromjs.push({ target: '/dirt/play', offset, params });
|
||||
}
|
||||
console.log(messagesfromjs);
|
||||
|
||||
if (messagesfromjs.length) {
|
||||
setTimeout(() => {
|
||||
Invoke('sendosc', { messagesfromjs });
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -1,9 +1,7 @@
|
||||
use rosc::encoder;
|
||||
use rosc::{ OscMessage, OscPacket, OscType };
|
||||
use std::net::{ SocketAddrV4, UdpSocket };
|
||||
use std::str::FromStr;
|
||||
use std::net::UdpSocket;
|
||||
use std::time::Duration;
|
||||
use std::{ env, f32 };
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{ mpsc, Mutex };
|
||||
use tokio::time::Instant;
|
||||
@ -18,9 +16,7 @@ pub struct OscMsg {
|
||||
pub struct AsyncInputTransmit {
|
||||
pub inner: Mutex<mpsc::Sender<Vec<OscMsg>>>,
|
||||
}
|
||||
fn get_addr_from_arg(arg: &str) -> SocketAddrV4 {
|
||||
SocketAddrV4::from_str(arg).unwrap()
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
async_input_receiver: mpsc::Receiver<Vec<OscMsg>>,
|
||||
mut async_output_receiver: mpsc::Receiver<Vec<OscMsg>>,
|
||||
@ -44,22 +40,17 @@ pub fn init(
|
||||
}
|
||||
}
|
||||
});
|
||||
println!("cloning message queue");
|
||||
|
||||
let message_queue_clone = Arc::clone(&message_queue);
|
||||
tauri::async_runtime::spawn(async move {
|
||||
println!("opening osc port");
|
||||
/* ...........................................................
|
||||
Open OSC Ports
|
||||
............................................................*/
|
||||
|
||||
let sock = UdpSocket::bind("localhost:57121").unwrap();
|
||||
let to_addr = String::from("localhost:57120");
|
||||
|
||||
let sock = UdpSocket::bind("127.0.0.1:57121").unwrap();
|
||||
let to_addr = String::from("127.0.0.1:57120");
|
||||
/* ...........................................................
|
||||
Process queued messages
|
||||
............................................................*/
|
||||
|
||||
loop {
|
||||
let mut message_queue = message_queue_clone.lock().await;
|
||||
println!("num messages {}", message_queue.len());
|
||||
@ -109,12 +100,10 @@ pub async fn sendosc(
|
||||
) -> Result<(), String> {
|
||||
let async_proc_input_tx = state.inner.lock().await;
|
||||
let mut messages_to_process: Vec<OscMsg> = Vec::new();
|
||||
|
||||
for m in messagesfromjs {
|
||||
let mut args = Vec::new();
|
||||
for p in m.params {
|
||||
args.push(OscType::String(p.name));
|
||||
|
||||
if p.valueisnumber {
|
||||
args.push(OscType::Float(p.value.parse().unwrap()));
|
||||
} else {
|
||||
|
||||
@ -37,10 +37,10 @@ const modules = [
|
||||
import('@strudel.cycles/core'),
|
||||
import('@strudel.cycles/tonal'),
|
||||
import('@strudel.cycles/mini'),
|
||||
isTauri() ? import('@strudel/desktopbridge') : import('@strudel.cycles/midi'),
|
||||
isTauri() ? import('@strudel/desktopbridge/midibridge.mjs') : import('@strudel.cycles/midi'),
|
||||
import('@strudel.cycles/xen'),
|
||||
import('@strudel.cycles/webaudio'),
|
||||
import('@strudel.cycles/osc'),
|
||||
isTauri() ? import('@strudel/desktopbridge/oscbridge.mjs') : import('@strudel.cycles/osc'),
|
||||
import('@strudel.cycles/serial'),
|
||||
import('@strudel.cycles/soundfonts'),
|
||||
import('@strudel.cycles/csound'),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user