Skip to main content

OpCtx

Struct OpCtx 

Source
pub struct OpCtx<'a> {
Show 20 fields pub command: String, pub inputs: Vec<PathBuf>, pub globals: Globals, pub io: &'a dyn AudioIo, pub progress: &'a dyn Progress, pub cancel: CancelToken, pub registry: Option<&'a Registry>, pub outputs: Vec<OutputRecord>, pub input_records: Vec<InputRecord>, pub warnings: Vec<WarningRecord>, pub metrics: Map<String, Value>, pub notes: Map<String, Value>, pub models: Vec<ModelRecord>, pub plugins: Vec<Value>, pub deterministic: Option<bool>, pub stdin: Option<Vec<u8>>, pub stdout: Option<Vec<u8>>, pub index: usize, pub temp_files: Vec<PathBuf>, pub result: Option<Value>,
}
Expand description

Context for one op invocation.

Fields§

§command: String

The command path being run (e.g. separate).

§inputs: Vec<PathBuf>§globals: Globals§io: &'a dyn AudioIo§progress: &'a dyn Progress§cancel: CancelToken§registry: Option<&'a Registry>

Registry of every op, for ops that compose others (master, enhance, hum…).

§outputs: Vec<OutputRecord>§input_records: Vec<InputRecord>§warnings: Vec<WarningRecord>§metrics: Map<String, Value>§notes: Map<String, Value>

Parameter values resolved at run time (detected key, chosen noise region…).

§models: Vec<ModelRecord>§plugins: Vec<Value>§deterministic: Option<bool>

False when a stage may be nondeterministic (plugins with internal randomness).

§stdin: Option<Vec<u8>>

Stdin bytes (when an input is -).

§stdout: Option<Vec<u8>>

Bytes to write to stdout when -o -.

§index: usize

Index of this item in a batch (for {index} in output templates).

§temp_files: Vec<PathBuf>

Files created by this op that must be removed if the op fails.

§result: Option<Value>

Result value set by a Transform op (custom ops return theirs directly).

Implementations§

Source§

impl<'a> OpCtx<'a>

Source

pub fn new( command: &str, inputs: Vec<PathBuf>, globals: Globals, io: &'a dyn AudioIo, progress: &'a dyn Progress, ) -> Self

Source

pub fn child(&self, command: &str, inputs: Vec<PathBuf>) -> OpCtx<'a>

A child context for running a nested op (shares io, progress, globals, registry).

Source

pub fn absorb(&mut self, child: OpCtx<'a>)

Merge a child’s records into this context.

Source

pub fn bpm(&self) -> Option<f64>

Source

pub fn seed(&self) -> u64

Source

pub fn input(&self, i: usize) -> Result<&Path>

Source

pub fn check_allowed(&self, path: &Path) -> Result<()>

Check that a path is inside the sandbox (when one is set).

Source

pub fn read_audio(&mut self, i: usize) -> Result<AudioBuffer>

Decode input i (or stdin for -), applying --channels/--sample-rate only at write time.

Source

pub fn read_audio_path(&mut self, path: &Path) -> Result<AudioBuffer>

Source

pub fn open_audio_stream( &mut self, i: usize, ) -> Result<Option<Box<dyn AudioReader>>>

Input i as a stream of chunks when the IO layer can stream it; Ok(None) means use OpCtx::read_audio. Call OpCtx::record_stream_input once the stream is consumed.

Source

pub fn record_stream_input( &mut self, info: &SourceInfo, sample_rate: u32, channels: usize, frames: u64, )

Record a streamed input as OpCtx::read_audio would (frames = what was decoded).

Source

pub fn note_input(&mut self, path: &Path)

Record a non-audio input (MIDI, score, profile…).

Source

pub fn output_path(&self, role: Option<&str>, ext: &str) -> Result<PathBuf>

Resolve the output path for this op.

  • role — e.g. vocals for a stem (fills {stem}); None for the main output.
  • ext — default extension when the user gave no -o.

Honours -o templates ({name}, {stem}, {index}, {ext}, {command}), --outdir, --in-place, and the default <input>.<command>[.<role>].<ext> beside the input.

Source

pub fn prepare_output(&self, path: &Path) -> Result<()>

Check overwrite policy and sandbox for an output path, creating its directory.

Source

pub fn encode_options(&self, path: &Path) -> EncodeOptions

Encoding options from global flags for a given output path.

Source

pub fn write_audio( &mut self, path: &Path, buf: &AudioBuffer, role: Option<&str>, ) -> Result<()>

Write an audio output, applying --sample-rate and --channels conversions is the caller’s job (the executor does it for transforms). Records the output.

Source

pub fn write_audio_with( &mut self, path: &Path, buf: &AudioBuffer, role: Option<&str>, opts: &EncodeOptions, ) -> Result<()>

Source

pub fn write_audio_blocks( &mut self, path: &Path, role: Option<&str>, opts: &EncodeOptions, sample_rate: u32, channels: usize, frames: usize, produce: &mut dyn FnMut(&mut dyn FnMut(&[&[f32]]) -> Result<()>) -> Result<()>, ) -> Result<()>

Write an audio output block by block: produce(sink) hands sink consecutive planar blocks covering exactly frames frames. The output streams to the encoder when the IO layer can (memory independent of the length); otherwise the blocks are collected and written with OpCtx::write_audio_with. The file’s bytes are the same either way.

Source

pub fn write_file( &mut self, path: &Path, bytes: &[u8], role: Option<&str>, ) -> Result<()>

Write a non-audio file (JSON, MIDI, text…) and record it.

Source

pub fn record_output(&mut self, path: &Path, role: Option<&str>)

Record an output that was written by other means (e.g. a helper process).

Source

pub fn set_result(&mut self, value: impl Serialize)

Set the envelope result from a Transform op.

Source

pub fn warn(&mut self, code: &str, message: impl Into<String>)

Source

pub fn metric(&mut self, key: &str, value: impl Serialize)

Source

pub fn note(&mut self, key: &str, value: impl Serialize)

Record a parameter resolved at run time (shown in params and the sidecar).

Source

pub fn model_used(&mut self, name: &str, version: &str, sha256: &str)

Source

pub fn set_progress(&self, fraction: f64)

Source

pub fn check_cancel(&self) -> Result<()>

Source

pub fn threads(&self) -> usize

Thread count to use (0 = all cores).

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for OpCtx<'a>

§

impl<'a> !UnwindSafe for OpCtx<'a>

§

impl<'a> Freeze for OpCtx<'a>

§

impl<'a> Send for OpCtx<'a>

§

impl<'a> Sync for OpCtx<'a>

§

impl<'a> Unpin for OpCtx<'a>

§

impl<'a> UnsafeUnpin for OpCtx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.