Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderVocke committed Dec 20, 2024
1 parent 40ab66b commit a4d6f70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/rust/backend_bindings/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ integer_enum! {

impl PortConnectabilityKind {
pub fn from_ffi(ffi_kind : u32) -> Self {
const INTERNAL : u32 = ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal as u32;
const EXTERNAL : u32 = ffi::shoop_port_connectability_t_ShoopPortConnectability_External as u32;
match ffi_kind {
0 => PortConnectabilityKind::None,
ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal => PortConnectabilityKind::Internal,
ffi::shoop_port_connectability_t_ShoopPortConnectability_External => PortConnectabilityKind::External,
INTERNAL => PortConnectabilityKind::Internal,
EXTERNAL => PortConnectabilityKind::External,
_ => panic!("Invalid PortConnectabilityKind value: {}", ffi_kind),
}
}
Expand All @@ -72,18 +74,18 @@ pub struct PortConnectability {
impl PortConnectability {
pub fn from_ffi(ffi_connectability : u32) -> Self {
PortConnectability {
internal : ffi_connectability & ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal != 0,
external : ffi_connectability & ffi::shoop_port_connectability_t_ShoopPortConnectability_External != 0,
internal : ffi_connectability & (ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal as u32) != 0,
external : ffi_connectability & (ffi::shoop_port_connectability_t_ShoopPortConnectability_External as u32) != 0,
}
}

pub fn to_ffi(&self) -> u32 {
let mut ffi_connectability = 0;
let mut ffi_connectability : u32 = 0;
if self.internal {
ffi_connectability |= ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal;
ffi_connectability |= (ffi::shoop_port_connectability_t_ShoopPortConnectability_Internal as u32);
}
if self.external {
ffi_connectability |= ffi::shoop_port_connectability_t_ShoopPortConnectability_External;
ffi_connectability |= (ffi::shoop_port_connectability_t_ShoopPortConnectability_External as u32);
}
ffi_connectability
}
Expand Down
10 changes: 5 additions & 5 deletions src/rust/backend_bindings/src/shoop_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ impl Loop {
pub fn add_audio_channel(&self, mode: ChannelMode) -> Result<AudioChannel, anyhow::Error> {
let guard = self.obj.lock().unwrap();
let obj = *guard;
let channel = unsafe { ffi::add_audio_channel(obj, mode as u32) };
let channel = unsafe { ffi::add_audio_channel(obj, (mode as u32).try_into().unwrap()) };
AudioChannel::new(channel)
}

pub fn add_midi_channel(&self, mode: ChannelMode) -> Result<MidiChannel, anyhow::Error> {
let guard = self.obj.lock().unwrap();
let obj = *guard;
let channel = unsafe { ffi::add_midi_channel(obj, mode as u32) };
let channel = unsafe { ffi::add_midi_channel(obj, (mode as u32).try_into().unwrap()) };
MidiChannel::new(channel)
}

Expand All @@ -90,7 +90,7 @@ impl Loop {
return Err(anyhow::anyhow!("Invalid backend object"));
}
unsafe {
ffi::loop_transition(obj, to_mode as u32, maybe_cycles_delay, maybe_to_sync_at_cycle)
ffi::loop_transition(obj, (to_mode as u32).try_into().unwrap(), maybe_cycles_delay, maybe_to_sync_at_cycle)
};
Ok(())
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Loop {
reverse_start_cycle,
cycles_length,
go_to_cycle,
go_to_mode as u32,
(go_to_mode as u32).try_into().unwrap(),
)
};
Ok(())
Expand All @@ -201,7 +201,7 @@ pub fn transition_multiple_loops(
ffi::loops_transition(
handles.len() as u32,
handles_ptr,
to_state as u32,
(to_state as u32).try_into().unwrap(),
maybe_cycles_delay,
maybe_to_sync_at_cycle,
)
Expand Down

0 comments on commit a4d6f70

Please sign in to comment.