Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ jobs:
- name: Install system packages
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:rncbc/libs-noble
sudo apt-get update
sudo apt-get install -y \
pkg-config \
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "maolan-engine"
version = "0.4.21"
version = "0.4.22"
edition = "2024"
description = "Audio engine for the Maolan DAW with audio/MIDI tracks, routing, export, and out-of-process CLAP/VST3/LV2 plugin support"
license = "BSD-2-Clause"
Expand Down
7 changes: 7 additions & 0 deletions src/audio/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ impl AudioIO {
Arc::new(live)
}

pub fn visit_connections(&self, mut visit: impl FnMut(&Arc<Self>)) {
let connections = self.connections.load();
for connection in connections.iter().filter_map(Weak::upgrade) {
visit(&connection);
}
}

pub fn store_connections(&self, connections: Vec<Arc<Self>>) {
let len = connections.len();
self.connections
Expand Down
19 changes: 11 additions & 8 deletions src/engine/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Engine {
/// thru-routing / MIDI-learn / step-record (already delivered to track
/// ports by the cycle thread, so they are not buffered again).
pub(crate) async fn drain_inline_outcome(&mut self) {
let Some(outcome) = self.inline_render.take_outcome() else {
let Some(mut outcome) = self.inline_render.take_outcome() else {
return;
};
if outcome.stale {
Expand All @@ -160,19 +160,21 @@ impl Engine {
self.advance_render_clock(outcome.skipped_frames as usize);
self.inline_render.invalidate_anchor();
}
if let Some(plan) = outcome.plan {
for result in outcome.results {
if let Some(plan) = outcome.plan.take() {
for result in &mut outcome.results {
if let Some(Op::Task { task, .. }) = plan.nodes.get(result.node as usize) {
let track = Self::task_track(task);
let track_name = Self::task_track_name(task);
let output_linear = track.lock().output_meter_linear();
self.meters
.track_meter_linear_by_track
.insert(track_name, result.output_linear);
.insert(track_name, output_linear);
}
if result.latency_changed {
self.publish_state_snapshot();
self.plan_builder.mark_dirty();
}
for action in result.parameter_updates {
for action in result.parameter_updates.drain(..) {
self.notify_clients(Ok(action)).await;
}
}
Expand All @@ -181,9 +183,10 @@ impl Engine {
self.apply_hw_out_meter_from_plan(&plan).await;
}
if !outcome.midi_in_events.is_empty() {
self.handle_hw_midi_in_events(outcome.midi_in_events, false)
self.handle_hw_midi_in_events(&mut outcome.midi_in_events, false)
.await;
}
self.inline_render.recycle_outcome(outcome);
}

/// Hardware MIDI-in event handling shared by the `HWMidiEvents` message
Expand All @@ -192,10 +195,10 @@ impl Engine {
/// forward (already delivered to ports; only thru/learn/step-record here).
pub(crate) async fn handle_hw_midi_in_events(
&mut self,
events: Vec<HwMidiEvent>,
events: &mut Vec<HwMidiEvent>,
buffer_for_ports: bool,
) {
for hw_event in events {
for hw_event in events.drain(..) {
let thru_targets: Vec<String> = self
.hw_midi
.midi_hw_thru_routes
Expand Down
2 changes: 1 addition & 1 deletion src/engine/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Engine {
continue;
}
let abs_sample = start as u64 + (frame - from) as u64;
entry.events.push((abs_sample, event.data.clone()));
entry.events.push((abs_sample, event.data.to_vec()));
}
}

Expand Down
32 changes: 13 additions & 19 deletions src/engine/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::workers::sndio_worker::HwWorker;
use crate::{
history::UndoEntry,
message::{Action, Message, ProcessTask},
state::TrackHandle,
};
use std::{
sync::atomic::Ordering,
Expand Down Expand Up @@ -182,16 +183,18 @@ impl Engine {
}
}

pub(crate) fn task_track_name(task: &ProcessTask) -> String {
pub(crate) fn task_track(task: &ProcessTask) -> &TrackHandle {
match task {
ProcessTask::Track(t) | ProcessTask::FolderInput(t) | ProcessTask::FolderOutput(t) => {
t.lock().name.clone()
}
ProcessTask::Track(t) | ProcessTask::FolderInput(t) | ProcessTask::FolderOutput(t) => t,
#[cfg(feature = "plugins")]
ProcessTask::Plugin { track, .. } => track.lock().name.clone(),
ProcessTask::Plugin { track, .. } => track,
}
}

pub(crate) fn task_track_name(task: &ProcessTask) -> String {
Self::task_track(task).lock().name.clone()
}

/// Pushes the current transport state into the task's track before the
/// task is dispatched.
///
Expand Down Expand Up @@ -357,7 +360,6 @@ impl Engine {
worker_id: usize,
epoch: u64,
node: u32,
output_linear: Vec<f32>,
parameter_updates: Vec<Action>,
latency_changed: bool,
) {
Expand All @@ -378,6 +380,7 @@ impl Engine {
}
let plan = self.executor.plan().clone();
if let Some(crate::render_plan::Op::Task { task, .. }) = plan.nodes.get(node as usize) {
let output_linear = Self::task_track(task).lock().output_meter_linear();
let track_name = Self::task_track_name(task);
self.meters
.track_meter_linear_by_track
Expand Down Expand Up @@ -415,7 +418,6 @@ impl Engine {
result.worker_id,
result.epoch,
result.node,
result.output_linear,
result.parameter_updates,
result.latency_changed,
)
Expand Down Expand Up @@ -961,19 +963,11 @@ impl Engine {
worker_id,
epoch,
node,
output_linear,
parameter_updates,
latency_changed,
} => {
self.on_node_done(
worker_id,
epoch,
node,
output_linear,
parameter_updates,
latency_changed,
)
.await;
self.on_node_done(worker_id, epoch, node, parameter_updates, latency_changed)
.await;
}
Message::Channel(s) => {
self.clients.push(s);
Expand Down Expand Up @@ -1007,15 +1001,15 @@ impl Engine {
self.handle_hw_finished().await;
self.drain_iodelay_report().await;
}
Message::HWMidiEvents(events) => {
Message::HWMidiEvents(mut events) => {
// Events from the hw worker's between-cycle drains; they
// are buffered for the track-port push (which the pool
// path runs in `handle_hw_finished` and the inline path
// runs in the Go sender). Events forwarded by the inline
// cycle thread arrive via `drain_inline_outcome` already
// delivered to the ports and call this with
// `buffer_for_ports = false`.
self.handle_hw_midi_in_events(events, true).await;
self.handle_hw_midi_in_events(&mut events, true).await;
}
Message::StartAudioPreview {
samples,
Expand Down
2 changes: 1 addition & 1 deletion src/hw/coreaudio/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ unsafe fn collect_packets(context: &InputCallbackContext, packet_list: *const Mi
if let Ok(mut events) = context.queue.lock() {
events.push(HwMidiEvent {
device: context.device.clone(),
event: MidiEvent::new(0, data.to_vec()),
event: MidiEvent::from_slice(0, data),
});
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/hw/jack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct Process {
/// RT side of the MIDI-out ring: this callback is the sole consumer, the
/// engine thread produces after each completed cycle.
midi_out_consumer: rtrb::Consumer<MidiEvent>,
midi_out_scratch: Vec<MidiEvent>,
/// In-events dropped because the engine did not drain fast enough.
midi_in_dropped: Arc<AtomicU64>,
output_gain_linear: Arc<AtomicU32>,
Expand Down Expand Up @@ -188,7 +189,7 @@ impl Process {
fn collect_midi_input(&mut self, ps: &ProcessScope) {
for port in &self.midi_in_ports {
for raw in port.iter(ps) {
let event = MidiEvent::new(raw.time, raw.bytes.to_vec());
let event = MidiEvent::from_slice(raw.time, raw.bytes);
if self.midi_in_producer.push(event).is_err() {
self.midi_in_dropped.fetch_add(1, Ordering::Relaxed);
}
Expand All @@ -201,16 +202,16 @@ impl Process {
while self.midi_out_consumer.pop().is_ok() {}
return;
}
let mut events = Vec::new();
self.midi_out_scratch.clear();
while let Ok(event) = self.midi_out_consumer.pop() {
events.push(event);
self.midi_out_scratch.push(event);
}
if events.is_empty() {
if self.midi_out_scratch.is_empty() {
return;
}
for out_port in &mut self.midi_out_ports {
let mut writer = out_port.writer(ps);
for event in &events {
for event in &self.midi_out_scratch {
let raw = RawMidi {
time: event.frame,
bytes: &event.data,
Expand Down Expand Up @@ -384,6 +385,7 @@ impl JackRuntime {
plan_slot,
midi_in_producer,
midi_out_consumer,
midi_out_scratch: Vec::new(),
midi_in_dropped: midi_in_dropped.clone(),
output_gain_linear: output_gain_linear.clone(),
output_balance: output_balance.clone(),
Expand Down
20 changes: 10 additions & 10 deletions src/hw/midi_hub.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::message::HwMidiEvent;
use crate::midi::io::MidiEvent;
use crate::midi::io::{MidiData, MidiEvent};
use nix::libc;
use std::{
fs::File,
Expand Down Expand Up @@ -591,24 +591,24 @@ struct MidiParser {
}

impl MidiParser {
fn feed(&mut self, byte: u8) -> Option<Vec<u8>> {
fn feed(&mut self, byte: u8) -> Option<MidiData> {
if byte & 0x80 != 0 {
if self.in_sysex {
if byte == 0xF7 {
self.sysex.push(byte);
self.in_sysex = false;
return Some(std::mem::take(&mut self.sysex));
return Some(MidiData::Heap(std::mem::take(&mut self.sysex)));
}

if byte >= 0xF8 {
return Some(vec![byte]);
return Some(MidiData::from_slice(&[byte]));
}

self.in_sysex = false;
self.sysex.clear();
}
if byte >= 0xF8 {
return Some(vec![byte]);
return Some(MidiData::from_slice(&[byte]));
}
if byte == 0xF0 {
self.in_sysex = true;
Expand All @@ -623,7 +623,7 @@ impl MidiParser {
self.len = 0;
self.needed = status_data_len(byte);
if self.needed == 0 {
return Some(vec![byte]);
return Some(MidiData::from_slice(&[byte]));
}
return None;
}
Expand All @@ -642,15 +642,15 @@ impl MidiParser {
return None;
}

let mut message = Vec::with_capacity(1 + self.needed);
message.push(status);
message.extend_from_slice(&self.data[..self.needed]);
let mut message = [0; 3];
message[0] = status;
message[1..1 + self.needed].copy_from_slice(&self.data[..self.needed]);
self.len = 0;
if status >= 0xF0 {
self.status = None;
self.needed = 0;
}
Some(message)
Some(MidiData::from_slice(&message[..1 + self.needed]))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/hw/oss/audio_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ mod tests {
format: super::super::AFMT_U8,
chsamples: 4,
buffer: vec![0; 4],
raw_buffer: vec![],
f32_buffer: vec![],
buffer_info: BufferInfo {
fragments: 2,
Expand Down
Loading
Loading