Skip to content

Commit

Permalink
Feature-gate debug prints in audio thread.
Browse files Browse the repository at this point in the history
When prints are enabled, then allocation checking is disabled
because println!() can allocate memory.
  • Loading branch information
Windfisch committed May 10, 2021
1 parent 6500b3c commit ae3c084
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ stable_deref_trait = "1.0.0"

[patch.crates-io]
rocket = {git="https://github.com/SergioBenitez/Rocket", branch="master"}

[features]
debug_print_in_audio_thread = ["assert_no_alloc/warn_debug"]
13 changes: 12 additions & 1 deletion src/engine/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>
std::mem::swap(&mut self.devices[id], &mut devtuple);

if let Some((old, _)) = devtuple {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("submitting deconstruction request");
if self.destructor_channel.push(DestructionRequest::AudioDevice(old)).is_err() {
panic!("Failed to submit deconstruction request");
Expand All @@ -216,6 +217,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>
std::mem::swap(&mut self.mididevices[id], &mut devtuple);

if let Some((old, _)) = devtuple {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("submitting deconstruction request");
if self.destructor_channel.push(DestructionRequest::MidiDevice(old)).is_err() {
panic!("Failed to submit deconstruction request");
Expand All @@ -231,10 +233,15 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>
self.mididevices[id].as_mut().unwrap().1.stop_transport_pending = true;
}
Message::NewAudioTake(take) => {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\ngot take");
self.audiotakes.push_back(take);
}
Message::NewMidiTake(take) => { println!("\ngot miditake"); self.miditakes.push_back(take); }
Message::NewMidiTake(take) => {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\ngot miditake");
self.miditakes.push_back(take);
}
Message::FinishAudioTake(id, length) => {
for_take!(&mut self.audiotakes, id, t -> {
t.length = Some(length);
Expand Down Expand Up @@ -348,6 +355,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>

if let Some(length) = t.length {
if t.recorded_length >= length {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\nFinished recording on device {}", t.audiodev_id);
self.event_channel.send_or_complain(Event::AudioTakeStateChanged(t.audiodev_id, t.id, RecordState::Finished, t.started_recording_at + length));
t.record_state = Finished;
Expand All @@ -356,6 +364,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>
}
else if t.record_state == Waiting {
if song_wraps {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\nStarted recording on device {}", t.audiodev_id);
self.event_channel.send_or_complain(Event::AudioTakeStateChanged(t.audiodev_id, t.id, RecordState::Recording, self.transport_position + song_wraps_at));
t.record_state = Recording;
Expand Down Expand Up @@ -386,6 +395,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>

if let Some(length) = t.length {
if t.recorded_length >= length {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\nFinished recording on device {}", t.mididev_id);
self.event_channel.send_or_complain(Event::MidiTakeStateChanged(t.mididev_id, t.id, RecordState::Finished, t.started_recording_at + length));
t.record_state = Finished;
Expand All @@ -394,6 +404,7 @@ impl<Driver: DriverTrait> AudioThreadState<Driver>
}
else if t.record_state == Waiting {
if song_wraps {
#[cfg(feature = "debug_print_in_audio_thread")]
println!("\nStarted recording on device {}", t.mididev_id);
self.event_channel.send_or_complain(Event::MidiTakeStateChanged(t.mididev_id, t.id, RecordState::Recording, self.transport_position + song_wraps_at));
t.record_state = Recording;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/takes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl MidiTake {

if last_timestamp_before_loop < self.playback_position + range.len() as u32 {
// rewind only when the song actually passes the take length
#[cfg(feature = "debug_print_in_audio_thread")]
println!("MIDI REWIND");
self.events.rewind();

Expand Down Expand Up @@ -307,6 +308,7 @@ impl MidiTake {
if range.contains(&event.time()) {
if event.bytes().len() != 3 {
// FIXME
#[cfg(feature = "debug_print_in_audio_thread")]
println!("ignoring event with length != 3");
}
else {
Expand Down

0 comments on commit ae3c084

Please sign in to comment.