Skip to content

Commit

Permalink
Execute integration test using futures
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Jan 24, 2025
1 parent 3b2b6c0 commit 2d39bb6
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 34,722 deletions.
4 changes: 2 additions & 2 deletions main/high/src/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Fx {
Ok(res)
}

pub fn state_chunk(&self) -> Result<ChunkRegion, &'static str> {
pub fn state_chunk(&self) -> ReaperResult<ChunkRegion> {
let res = self
.tag_chunk()?
.move_left_cursor_right_to_start_of_next_line()
Expand Down Expand Up @@ -496,7 +496,7 @@ impl Fx {
// reconsider the ownership requirement of ChunkRegions as a whole (but then we need to
// care about lifetimes).
// TODO-low Supports track FX only
pub fn set_chunk(&self, chunk_region: ChunkRegion) -> Result<(), &'static str> {
pub fn set_chunk(&self, chunk_region: ChunkRegion) -> ReaperResult<()> {
// First replace GUID in chunk with the one of this FX
let mut parent_chunk = chunk_region.parent_chunk();
if let Some(fx_id_line) = chunk_region.find_line_starting_with("FXID ") {
Expand Down
11 changes: 6 additions & 5 deletions main/high/src/fx_chain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::fx::{get_fx_guid, Fx};
use crate::guid::Guid;
use crate::{
get_track_fx_location, Chunk, ChunkRegion, Project, Reaper, Take, Track, MAX_TRACK_CHUNK_SIZE,
get_track_fx_location, Chunk, ChunkRegion, Project, Reaper, ReaperError, Take, Track,
MAX_TRACK_CHUNK_SIZE,
};

use crate::error::ReaperResult;
Expand Down Expand Up @@ -246,7 +247,7 @@ impl FxChain {
Ok(())
}

pub fn add_fx_from_chunk(&self, chunk: &str) -> Result<Fx, &'static str> {
pub fn add_fx_from_chunk(&self, chunk: &str) -> ReaperResult<Fx> {
let mut track_chunk = self
.track_fx_track()
.ok_or("working on track FX only")?
Expand Down Expand Up @@ -279,7 +280,7 @@ DOCKED 0
self.track_fx_track()
.ok_or("working on track FX only")?
.set_chunk(track_chunk)?;
self.last_fx().ok_or("FX not added")
self.last_fx().ok_or(ReaperError::new("FX not added"))
}

// Returned FX has GUIDs set
Expand Down Expand Up @@ -311,7 +312,7 @@ DOCKED 0

// In Track this returns Chunk, here it returns ChunkRegion. Because REAPER always returns
// the chunk of the complete track, not just of the FX chain.
pub fn chunk(&self) -> Result<Option<ChunkRegion>, &'static str> {
pub fn chunk(&self) -> ReaperResult<Option<ChunkRegion>> {
let chunk = self
.track_fx_track()
.ok_or("working on track FX only")?
Expand All @@ -320,7 +321,7 @@ DOCKED 0
Ok(res)
}

pub fn set_chunk(&self, chunk: &str) -> Result<(), &'static str> {
pub fn set_chunk(&self, chunk: &str) -> ReaperResult<()> {
let mut track_chunk = self
.track_fx_track()
.ok_or("works on track FX only")?
Expand Down
1 change: 1 addition & 0 deletions main/high/src/main_future_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{local_run_loop_executor, run_loop_executor, Reaper};
use std::error::Error;
use tracing::warn;

#[derive(Clone)]
pub struct FutureSupport {
main_thread_future_spawner: run_loop_executor::Spawner,
local_main_thread_future_spawner: local_run_loop_executor::Spawner,
Expand Down
4 changes: 2 additions & 2 deletions main/high/src/pan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Reaper;
use crate::{Reaper, ReaperError};
use reaper_medium::{ReaperPanValue, ReaperWidthValue};
use std::fmt;
use std::str::FromStr;
Expand Down Expand Up @@ -27,7 +27,7 @@ impl Pan {
}

impl FromStr for Pan {
type Err = &'static str;
type Err = ReaperError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
// At the moment this doesn't fail. But in future we could add extra checks.
Expand Down
9 changes: 5 additions & 4 deletions main/high/src/reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ impl Reaper {
/// - Registers post command hooks (to inform listeners of executed actions)
/// - Registers toggle actions (to report action on/off states)
/// - Registers all previously defined actions
pub fn wake_up(&self) -> Result<(), &'static str> {
pub fn wake_up(&self) -> ReaperResult<()> {
let reaper_main = self.reaper_main.get();
let mut session_status = reaper_main.session_status.borrow_mut();
if matches!(session_status.deref(), SessionStatus::Awake(_)) {
return Err("Session is already awake");
return Err("Session is already awake".into());
}
debug!("Waking up...");
// Functions
Expand Down Expand Up @@ -349,10 +349,10 @@ impl Reaper {
Ok(())
}

pub fn go_to_sleep(&self) -> Result<(), &'static str> {
pub fn go_to_sleep(&self) -> ReaperResult<()> {
let mut session_status = self.reaper_main.get().session_status.borrow_mut();
let awake_state = match session_status.deref() {
SessionStatus::Sleeping => return Err("Session is already sleeping"),
SessionStatus::Sleeping => return Err("Session is already sleeping".into()),
SessionStatus::Awake(s) => s,
};
debug!("Going to sleep...");
Expand Down Expand Up @@ -753,6 +753,7 @@ fn register_action(
}
}

use crate::error::ReaperResult;
#[cfg(feature = "sentry")]
pub use sentry_impl::SentryConfig;

Expand Down
13 changes: 8 additions & 5 deletions main/high/src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::guid::Guid;
use crate::track_route::TrackRoute;

use crate::{
Chunk, ChunkRegion, Item, Pan, Project, Reaper, SendPartnerType, TrackRoutePartner, Width,
Chunk, ChunkRegion, Item, Pan, Project, Reaper, ReaperError, SendPartnerType,
TrackRoutePartner, Width,
};

use crate::error::ReaperResult;
Expand Down Expand Up @@ -898,7 +899,7 @@ impl Track {
}
}

pub fn enable_auto_arm(&self) -> Result<(), &'static str> {
pub fn enable_auto_arm(&self) -> ReaperResult<()> {
let mut chunk = self.chunk(MAX_TRACK_CHUNK_SIZE, ChunkCacheHint::NormalMode)?;
if get_auto_arm_chunk_line(&chunk).is_some() {
return Ok(());
Expand All @@ -922,7 +923,7 @@ impl Track {
Ok(())
}

pub fn disable_auto_arm(&self) -> Result<(), &'static str> {
pub fn disable_auto_arm(&self) -> ReaperResult<()> {
let chunk = {
let auto_arm_chunk_line = match self.auto_arm_chunk_line()? {
None => return Ok(()),
Expand Down Expand Up @@ -1250,8 +1251,10 @@ impl Track {
}

// TODO-low Report possible error
pub fn set_chunk(&self, chunk: Chunk) -> Result<(), &'static str> {
let string: String = chunk.try_into().map_err(|_| "unfortunate")?;
pub fn set_chunk(&self, chunk: Chunk) -> ReaperResult<()> {
let string: String = chunk
.try_into()
.map_err(|_| ReaperError::new("unfortunate"))?;
let _ = unsafe {
Reaper::get().medium_reaper().set_track_state_chunk(
self.raw_unchecked(),
Expand Down
Loading

0 comments on commit 2d39bb6

Please sign in to comment.