-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9576096
commit 6fdca25
Showing
10 changed files
with
225 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use anyhow; | ||
use crate::ffi; | ||
use std::sync::Mutex; | ||
|
||
use crate::audio_driver::AudioDriver; | ||
use crate::port::PortDirection; | ||
|
||
pub struct DecoupledMidiPort { | ||
obj : Mutex<*mut ffi::shoopdaloop_decoupled_midi_port_t>, | ||
} | ||
|
||
unsafe impl Send for DecoupledMidiPort {} | ||
unsafe impl Sync for DecoupledMidiPort {} | ||
|
||
impl DecoupledMidiPort { | ||
pub fn new_driver_port(audio_driver : &AudioDriver, | ||
name_hint : &str, | ||
direction : &PortDirection) -> Result<Self, anyhow::Error> | ||
{ | ||
let name_hint_ptr = name_hint.as_ptr() as *const i8; | ||
let obj = unsafe { ffi::open_decoupled_midi_port | ||
(audio_driver.unsafe_backend_ptr(), | ||
name_hint_ptr, | ||
*direction as u32) }; | ||
if obj.is_null() { | ||
return Err(anyhow::anyhow!("Failed to create audio port")); | ||
} | ||
Ok(DecoupledMidiPort { | ||
obj : Mutex::new(obj), | ||
}) | ||
} | ||
|
||
pub fn unsafe_port_from_raw_ptr(ptr : usize) -> Self { | ||
DecoupledMidiPort { | ||
obj : Mutex::new(ptr as *mut ffi::shoopdaloop_decoupled_midi_port_t), | ||
} | ||
} | ||
|
||
pub unsafe fn unsafe_backend_ptr(&self) -> *mut ffi::shoopdaloop_decoupled_midi_port_t { | ||
let guard = self.obj.lock().unwrap(); | ||
*guard | ||
} | ||
} | ||
|
||
impl Drop for DecoupledMidiPort { | ||
fn drop(&mut self) { | ||
let guard = self.obj.lock().unwrap(); | ||
let obj = *guard; | ||
if obj.is_null() { | ||
return; | ||
} | ||
unsafe { ffi::close_decoupled_midi_port(obj) }; | ||
unsafe { ffi::destroy_shoopdaloop_decoupled_midi_port(obj) }; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use anyhow; | ||
use crate::ffi; | ||
use std::sync::Mutex; | ||
use crate::integer_enum; | ||
|
||
use crate::backend_session::BackendSession; | ||
|
||
integer_enum! { | ||
pub enum FXChainType { | ||
CarlaRack = ffi::shoop_fx_chain_type_t_Carla_Rack, | ||
CarlaPatchbay = ffi::shoop_fx_chain_type_t_Carla_Patchbay, | ||
CarlaPatchbay16x = ffi::shoop_fx_chain_type_t_Carla_Patchbay_16x, | ||
Test2x2x1 = ffi::shoop_fx_chain_type_t_Test2x2x1, | ||
} | ||
} | ||
|
||
pub struct FXChain { | ||
obj : Mutex<*mut ffi::shoopdaloop_fx_chain_t>, | ||
} | ||
|
||
unsafe impl Send for FXChain {} | ||
unsafe impl Sync for FXChain {} | ||
|
||
impl FXChain { | ||
pub fn new(backend_session : &BackendSession, | ||
chain_type : &FXChainType, | ||
title : &str) -> Result<Self, anyhow::Error> { | ||
let title_ptr = title.as_ptr() as *const i8; | ||
let obj = unsafe { ffi::create_fx_chain | ||
(backend_session.unsafe_backend_ptr(), | ||
*chain_type as u32, | ||
title_ptr) }; | ||
if obj.is_null() { | ||
return Err(anyhow::anyhow!("Failed to create FX chain")); | ||
} | ||
Ok(FXChain { | ||
obj : Mutex::new(obj), | ||
}) | ||
} | ||
|
||
pub unsafe fn unsafe_backend_ptr(&self) -> *mut ffi::shoopdaloop_fx_chain_t { | ||
let guard = self.obj.lock().unwrap(); | ||
*guard | ||
} | ||
} | ||
|
||
impl Drop for FXChain { | ||
fn drop(&mut self) { | ||
let guard = self.obj.lock().unwrap(); | ||
let obj = *guard; | ||
if obj.is_null() { | ||
return; | ||
} | ||
unsafe { ffi::destroy_fx_chain(obj) }; | ||
} | ||
} |
This file contains 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
38 changes: 38 additions & 0 deletions
38
src/rust/shoopdaloop/src/shoop_py_backend/decoupled_midi_port.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// See audio_port.rs from backend_bindings | ||
|
||
use pyo3::prelude::*; | ||
// use pyo3::exceptions::*; | ||
use backend_bindings; | ||
|
||
use crate::shoop_py_backend::audio_driver::AudioDriver; | ||
|
||
#[pyclass] | ||
pub struct DecoupledMidiPort { | ||
pub obj : backend_bindings::DecoupledMidiPort, | ||
} | ||
|
||
#[pymethods] | ||
impl DecoupledMidiPort { | ||
fn unsafe_backend_ptr (&self) -> usize { | ||
unsafe { self.obj.unsafe_backend_ptr() as usize } | ||
} | ||
} | ||
|
||
#[pyfunction] | ||
pub fn open_driver_decoupled_midi_port<'py> | ||
(audio_driver : &AudioDriver, | ||
name_hint : &str, | ||
direction : i32) -> PyResult<DecoupledMidiPort> { | ||
let dir = backend_bindings::PortDirection::try_from(direction).unwrap(); | ||
Ok(DecoupledMidiPort { obj: backend_bindings::DecoupledMidiPort::new_driver_port | ||
(&audio_driver.obj, | ||
name_hint, | ||
&dir) | ||
.unwrap() }) | ||
} | ||
|
||
pub fn register_in_module<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> { | ||
m.add_class::<DecoupledMidiPort>()?; | ||
m.add_function(wrap_pyfunction!(open_driver_decoupled_midi_port, m)?)?; | ||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// See shoop_loop.rs from backend_bindings | ||
|
||
use pyo3::prelude::*; | ||
// use pyo3::exceptions::*; | ||
use backend_bindings; | ||
|
||
use crate::shoop_py_backend::backend_session::BackendSession; | ||
|
||
#[pyclass] | ||
pub struct FXChain { | ||
pub obj : backend_bindings::FXChain, | ||
} | ||
|
||
#[pymethods] | ||
impl FXChain { | ||
#[new] | ||
fn py_new(backend_session : &BackendSession, | ||
chain_type : u32, | ||
title : &str) -> PyResult<Self> { | ||
Ok(FXChain { obj: backend_bindings::FXChain::new | ||
(&backend_session.obj, | ||
&backend_bindings::FXChainType::try_from(chain_type).unwrap(), | ||
title).unwrap() }) | ||
} | ||
|
||
fn unsafe_backend_ptr (&self) -> usize { | ||
unsafe { self.obj.unsafe_backend_ptr() as usize } | ||
} | ||
} | ||
|
||
pub fn register_in_module<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> { | ||
m.add_class::<FXChain>()?; | ||
Ok(()) | ||
} |
This file contains 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