Skip to content

Commit

Permalink
Medium-level API: Add calc_media_src_loudness
Browse files Browse the repository at this point in the history
It requires user to use `get_set_project_info_string_get` from the helgoboss#68.
  • Loading branch information
Levitanus committed Nov 15, 2022
1 parent 132dc73 commit 0d2528c
Showing 1 changed file with 125 additions and 2 deletions.
127 changes: 125 additions & 2 deletions main/medium/src/reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,29 @@ impl<UsageScope> Reaper<UsageScope> {
self.low().BypassFxAllTracks(byp);
}

/// Calculates loudness statistics of media via dry run render.
///
/// Statistics will be displayed to the user.
///
/// call GetSetProjectInfo_String("RENDER_STATS") to retrieve via API.
///
/// Returns Ok(()) if loudness was calculated successfully,
/// Err("User aborted render") if user canceled the dry run render,
/// Err("Unexpected result") if something went wrong.
pub unsafe fn calc_media_src_loudness(
&self,
media_source: PcmSource,
) -> ReaperFunctionResult<()>
where
UsageScope: MainThreadOnly,
{
match self.low().CalcMediaSrcLoudness(media_source.as_ptr()) {
1 => Ok(()),
-1 => Err(ReaperFunctionError::new("User aborted render.")),
_ => Err(ReaperFunctionError::new("Unexpected result.")),
}
}

/// Starts playing.
pub fn csurf_on_play(&self)
where
Expand Down Expand Up @@ -1161,11 +1184,11 @@ impl<UsageScope> Reaper<UsageScope> {
}

/// True if function name exists in the REAPER API
pub fn api_exists(&self, function_name: ReaperStringArg) -> bool
pub fn api_exists<'a, I: Into<ReaperStringArg<'a>>>(&self, function_name: I) -> bool
where
UsageScope: MainThreadOnly,
{
unsafe { self.low().APIExists(function_name.as_ptr()) }
unsafe { self.low().APIExists(function_name.into().as_ptr()) }
}

/// Displays a message window if the API was successfully called.
Expand Down Expand Up @@ -5808,6 +5831,106 @@ impl<UsageScope> Reaper<UsageScope> {
NonNull::new(ptr)
}

/// Save project with given filename and options.
///
/// # Safety
///
/// REAPER can crash if you pass an invalid project.
pub unsafe fn save_project(&self, project: ProjectContext, force_save_as: bool)
where
UsageScope: MainThreadOnly,
{
self.low().Main_SaveProject(project.to_raw(), force_save_as);
}

/// Save project with given filename and options.
///
/// # Safety
///
/// REAPER can crash if you pass an invalid project.
pub unsafe fn save_project_ex<'a, I: Into<ReaperStringArg<'a>>>(
&self,
project: ProjectContext,
file_name: I,
options: BitFlags<SaveProjectFlags>,
) where
UsageScope: MainThreadOnly,
{
self.low().Main_SaveProjectEx(
project.to_raw(),
file_name.into().as_ptr(),
options.bits_c() as i32,
);
}

/// Set project information.
///
/// For more information of possible values see `ProjectInfoStringCategory`
/// documentation.
///
/// # Known bugs
///
/// This function constantly returns false, but sometimes it works.
///
/// # Safety
///
/// REAPER can crash if you pass an invalid project.
pub unsafe fn get_set_project_info_string_set<'a, I: Into<ReaperStringArg<'a>>>(
&self,
project: ProjectContext,
category: ProjectInfoStringCategory,
value: I,
) -> bool
where
UsageScope: MainThreadOnly,
{
let val: ReaperStringArg = value.into();
let val: CString = CString::from(val.as_reaper_str().as_c_str());
self.low().GetSetProjectInfo_String(
project.to_raw(),
category.to_raw().as_ptr(),
val.into_raw(),
true,
)
}

/// Get project information.
///
/// For more information of possible values see `ProjectInfoStringCategory`
/// documentation.
///
/// # Known bugs
///
/// There are problems with several categories. At least, with
/// TrackGroupName(x), which makes definitely right string for category,
/// but doesn't work with reaper-rs.
///
/// # Safety
///
/// REAPER can crash if you pass an invalid project.
pub unsafe fn get_set_project_info_string_get(
&self,
project: ProjectContext,
category: ProjectInfoStringCategory,
) -> ReaperFunctionResult<String>
where
UsageScope: MainThreadOnly,
{
let max_size = 1024 * 10;
let (result, status) = with_string_buffer(max_size, |buf, _| -> bool {
self.low().GetSetProjectInfo_String(
project.to_raw(),
category.to_raw().as_ptr(),
buf,
false,
)
});
match status {
true => Ok(result.into_string()),
false => Err(ReaperFunctionError::new("Can not get project info.")),
}
}

/// Returns the take that is currently being edited in the given MIDI editor.
///
/// # Safety
Expand Down

0 comments on commit 0d2528c

Please sign in to comment.