Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a audio preview API #1702

Merged
merged 3 commits into from Jan 16, 2023
Merged

Add a audio preview API #1702

merged 3 commits into from Jan 16, 2023

Conversation

cfillion
Copy link
Collaborator

@cfillion cfillion commented Nov 6, 2022

Exposes REAPER's source preview API with additional features:

  • Full play rate / pitch support
  • Fade in/out (simple linear)
  • Apply volume when previewing through a track
  • Panning

Adds these features compared to the existing preview functions in js_ReaScript API:

  • Play through a project track
  • Change any parameter on the fly while preview is active (except source and length)
  • Query playback status (eg. position, peaks)
  • Measure align

Adds CF_PCM_Source_SetSectionInfo for previewing in reverse or limit the length (without requiring a MediaTake, unlike BR_SetMediaSourceProperties).

local source = reaper.PCM_Source_CreateFromFile(file)
if not source then return end

if reverse then
  local section = reaper.PCM_Source_CreateFromType('SECTION')
  reaper.CF_PCM_Source_SetSectionInfo(section, source, 0, 0, true)
  reaper.PCM_Source_Destroy(source)
  source = section
end

if preview then reaper.CF_Preview_Destroy(preview) end

preview = reaper.CF_CreatePreview(source)
if outToTrack then
  reaper.CF_Preview_SetOutputTrack(preview, outputProj, outputTrack)
else
  reaper.CF_Preview_SetValue(preview, 'I_OUTCHAN', outputChan)
end
reaper.CF_Preview_SetValue(preview, 'D_POSITION',     position)
reaper.CF_Preview_SetValue(preview, 'B_LOOP',         loop and 1 or 0)
reaper.CF_Preview_SetValue(preview, 'D_VOLUME',       volume)
reaper.CF_Preview_SetValue(preview, 'D_PAN',          pan)
reaper.CF_Preview_SetValue(preview, 'D_MEASUREALIGN', measureAlign)
reaper.CF_Preview_SetValue(preview, 'D_PLAYRATE',     playRate)
reaper.CF_Preview_SetValue(preview, 'D_PITCH',        pitch)
reaper.CF_Preview_SetValue(preview, 'B_PPITCH',       preservePitch and 1 or 0)
reaper.CF_Preview_SetValue(preview, 'I_PITCHMODE',    pitchMode)
reaper.CF_Preview_SetValue(preview, 'D_FADEINLEN',    fadeInLen)
reaper.CF_Preview_SetValue(preview, 'D_FADEOUTLEN',   fadeOutLen)
local length = reaper.CF_Preview_GetValue(preview, 'D_LENGTH')
reaper.CF_Preview_Play(preview)
reaper.PCM_Source_Destroy(source)

Test script

Test/demo script at https://gist.github.com/cfillion/7718bd7d3566a94c308ca7a5fdee8105.

@AppVeyorBot

This comment was marked as outdated.

@cfillion cfillion force-pushed the preview-api branch 2 times, most recently from 4ce5abe to 870f1d3 Compare November 6, 2022 02:59
@cfillion cfillion force-pushed the preview-api branch 2 times, most recently from 154e569 to 65f2f37 Compare November 6, 2022 04:25
@cfillion cfillion mentioned this pull request Nov 6, 2022
25 tasks
@AppVeyorBot

This comment was marked as outdated.

@AppVeyorBot

This comment was marked as outdated.

@cfillion cfillion force-pushed the preview-api branch 4 times, most recently from a071913 to 42b0392 Compare November 7, 2022 00:50
@AppVeyorBot

This comment was marked as outdated.

@AppVeyorBot

This comment was marked as outdated.

@AppVeyorBot

This comment was marked as outdated.

@AppVeyorBot

This comment was marked as outdated.

@AppVeyorBot

This comment was marked as outdated.

@cfillion cfillion merged commit 4068db0 into reaper-oss:master Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants