pub struct Engine { /* private fields */ }Expand description
This is the main moving part of the Second Music System. You create one of these, give it a delegate to handle music decoding, and “turn the handle” in your sound output code to make music come out.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(
sound_delegate: Arc<dyn SoundDelegate>,
speaker_layout: SpeakerLayout,
sample_rate: PosFloat,
num_threads: Option<NonZeroUsize>,
affinity: usize,
) -> Engine
pub fn new( sound_delegate: Arc<dyn SoundDelegate>, speaker_layout: SpeakerLayout, sample_rate: PosFloat, num_threads: Option<NonZeroUsize>, affinity: usize, ) -> Engine
Creates a new Engine with the given properties, which will perform
loading in the background using a purely internal Switchyard. Only
available if you haven’t disabled the "switchyard" feature.
Once these properties are set, they cannot be changed without creating a new Engine.
speaker_layout: What kind of speaker layout your listener has. When in doubt, useStereo.sample_rate: Number of samples per second you will be outputting.num_threads: Number of threads to use for decoding and streaming. IfNoneor 0, will use a reasonable default based on the number of available hardware threads and whether background loading is requested.num_threads: IfNone, will use a reasonable default based on the number of available hardware threads. IfSome(x), will use that exact number of hardware threads.affinity: Offset added to core affinity of threads. When in doubt, use0.
Sourcepub fn new_with_runtime<Runtime: TaskRuntime>(
sound_delegate: Arc<dyn SoundDelegate>,
speaker_layout: SpeakerLayout,
sample_rate: PosFloat,
loading_rt: Arc<Runtime>,
) -> Engine
pub fn new_with_runtime<Runtime: TaskRuntime>( sound_delegate: Arc<dyn SoundDelegate>, speaker_layout: SpeakerLayout, sample_rate: PosFloat, loading_rt: Arc<Runtime>, ) -> Engine
Creates a new Engine with the given properties using a particular custom
TaskRuntime for loading tasks. If you want
to perform offline rendering, or another task where you just want all
loading to happen synchronously, pass Arc::new(ForegroundTaskRuntime)
as the loading runtime. If you don’t care, and haven’t disabled the
switchyard feature, just use new instead.
Once these properties are set, they cannot be changed without creating a new Engine.
speaker_layout: What kind of speaker layout your listener has. When in doubt, useStereo.sample_rate: Number of samples per second you will be outputting.num_threads: Number of threads to use for decoding and streaming. IfNoneor 0, will use a reasonable default based on the number of available hardware threads and whether background loading is requested.
Sourcepub fn clone_commander(&self) -> Commander
pub fn clone_commander(&self) -> Commander
Makes an independent Commander that can send commands to this
Engine from another thread.
Sourcepub fn copy_live_soundtrack(&self) -> Soundtrack
pub fn copy_live_soundtrack(&self) -> Soundtrack
Gets a copy of the Soundtrack that is currently live.
Sourcepub fn copy_all_flow_controls(&self) -> HashMap<CompactString, StringOrNumber>
pub fn copy_all_flow_controls(&self) -> HashMap<CompactString, StringOrNumber>
Gets a copy of all the FlowControls.
Sourcepub fn get_speaker_layout(&self) -> SpeakerLayout
pub fn get_speaker_layout(&self) -> SpeakerLayout
Returns the SpeakerLayout this Engine was initialized for.
Sourcepub fn get_sample_rate(&self) -> PosFloat
pub fn get_sample_rate(&self) -> PosFloat
Returns the sample rate this Engine was initialized for.
Sourcepub fn turn_handle(&mut self, out: &mut [f32])
pub fn turn_handle(&mut self, out: &mut [f32])
Mix some audio, advance time! out must have a number of elements
divisible by the number of speaker channels. Any existing data in out
is mixed with the active music data. You may or may not want to zero
out before this call.
Trait Implementations§
Source§impl EngineCommands for Engine
impl EngineCommands for Engine
Source§fn begin_transaction(&mut self, length: Option<usize>) -> Transaction<'_, Self>
fn begin_transaction(&mut self, length: Option<usize>) -> Transaction<'_, Self>
Source§fn replace_soundtrack(&mut self, new_soundtrack: Soundtrack)
fn replace_soundtrack(&mut self, new_soundtrack: Soundtrack)
Source§fn precache(&mut self, flow_name: CompactString)
fn precache(&mut self, flow_name: CompactString)
is_flow_ready to determine when the loading is
complete. Read moreSource§fn unprecache(&mut self, flow_name: CompactString)
fn unprecache(&mut self, flow_name: CompactString)
Source§fn unprecache_all(&mut self)
fn unprecache_all(&mut self)
Source§fn is_flow_ready(&mut self, flow_name: CompactString) -> Response<bool> ⓘ
fn is_flow_ready(&mut self, flow_name: CompactString) -> Response<bool> ⓘ
query::Response that will
answer the question “Is this flow I precached now ready for instant
playback?”Source§fn is_flow_active(&mut self, flow_name: CompactString) -> Response<bool> ⓘ
fn is_flow_active(&mut self, flow_name: CompactString) -> Response<bool> ⓘ
query::Response that will
answer the question “Is this flow either currently playing or waiting
to start playing?” (After a flow reaches a natural end without looping,
this will return false.)Source§fn set_flow_control(
&mut self,
control_name: CompactString,
new_value: StringOrNumber,
)
fn set_flow_control( &mut self, control_name: CompactString, new_value: StringOrNumber, )
Source§fn get_flow_control(
&mut self,
control_name: CompactString,
) -> Response<Option<StringOrNumber>> ⓘ
fn get_flow_control( &mut self, control_name: CompactString, ) -> Response<Option<StringOrNumber>> ⓘ
query::Response that will
answer the question “What value does this flow control currently have?”
(Flows can set flow control values themselves, and in doing so,
communicate in a very limited way back to the calling program.)Source§fn get_all_flow_controls(
&mut self,
) -> Response<Vec<(CompactString, StringOrNumber)>> ⓘ
fn get_all_flow_controls( &mut self, ) -> Response<Vec<(CompactString, StringOrNumber)>> ⓘ
query::Response that will
give you a complete list of flow controls, and the values they are
currently set to.Source§fn get_active_flows(&mut self) -> Response<Vec<CompactString>> ⓘ
fn get_active_flows(&mut self) -> Response<Vec<CompactString>> ⓘ
query::Response that will
give you a complete list of flows that are playing.Source§fn get_active_nodes(&mut self) -> Response<Vec<ActiveNodeReport>> ⓘ
fn get_active_nodes(&mut self) -> Response<Vec<ActiveNodeReport>> ⓘ
query::Response that will
give you a complete list of flow nodes that are playing.Source§fn get_mix_control(
&mut self,
control_name: CompactString,
) -> Response<Option<f32>> ⓘ
fn get_mix_control( &mut self, control_name: CompactString, ) -> Response<Option<f32>> ⓘ
query::Response that will
answer the question “What volume level is this mix control currently
operating at?” If there is a fade in progress, the volume reported
will reflect the current moment within the fade.Source§fn get_all_mix_controls(&mut self) -> Response<Vec<(CompactString, f32)>> ⓘ
fn get_all_mix_controls(&mut self) -> Response<Vec<(CompactString, f32)>> ⓘ
query::Response that will
give you a complete list of mix controls, and the volumes they are
currently operating at. If there is a fade in progress, the volumes
reported will reflect the current moment within the fade.Source§fn get_mix_flows(&mut self) -> Response<Vec<MixFlowReport>> ⓘ
fn get_mix_flows(&mut self) -> Response<Vec<MixFlowReport>> ⓘ
query::Response that will
give you a complete list of flows that are playing, and the volumes
they’re playing at.Source§fn clear_flow_control(&mut self, control_name: CompactString)
fn clear_flow_control(&mut self, control_name: CompactString)
Source§fn clear_prefixed_flow_controls(&mut self, control_prefix: CompactString)
fn clear_prefixed_flow_controls(&mut self, control_prefix: CompactString)
Source§fn clear_all_flow_controls(&mut self)
fn clear_all_flow_controls(&mut self)
Source§fn fade_mix_control_to(
&mut self,
control_name: CompactString,
target_volume: PosFloat,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_mix_control_to( &mut self, control_name: CompactString, target_volume: PosFloat, fade_length: PosFloat, fade_type: FadeType, )
Source§fn fade_prefixed_mix_controls_to(
&mut self,
control_prefix: CompactString,
target_volume: PosFloat,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_prefixed_mix_controls_to( &mut self, control_prefix: CompactString, target_volume: PosFloat, fade_length: PosFloat, fade_type: FadeType, )
Source§fn fade_all_mix_controls_to(
&mut self,
target_volume: PosFloat,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_all_mix_controls_to( &mut self, target_volume: PosFloat, fade_length: PosFloat, fade_type: FadeType, )
main, to
the given volume (0.0 to 1.0), using the given fading curve, over the
given time period (in seconds). Read moreSource§fn fade_all_mix_controls_except_main_to(
&mut self,
target_volume: PosFloat,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_all_mix_controls_except_main_to( &mut self, target_volume: PosFloat, fade_length: PosFloat, fade_type: FadeType, )
main, to the
given volume (0.0 to 1.0), using the given fading curve, over the given
time period (in seconds). Read moreSource§fn fade_mix_control_out(
&mut self,
control_name: CompactString,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_mix_control_out( &mut self, control_name: CompactString, fade_length: PosFloat, fade_type: FadeType, )
Source§fn fade_prefixed_mix_controls_out(
&mut self,
control_prefix: CompactString,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_prefixed_mix_controls_out( &mut self, control_prefix: CompactString, fade_length: PosFloat, fade_type: FadeType, )
Source§fn fade_all_mix_controls_out(
&mut self,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_all_mix_controls_out( &mut self, fade_length: PosFloat, fade_type: FadeType, )
main,
to zero volume, using the given fading curve, over the given time
period (in seconds). When the fade is complete, the MixControl will be
removed from existence rather than simply zeroed; future commands to
“prefixed” and “all” will not resuscitate it (unless it is the target
of a future, specific command). Read moreSource§fn fade_all_mix_controls_except_main_out(
&mut self,
fade_length: PosFloat,
fade_type: FadeType,
)
fn fade_all_mix_controls_except_main_out( &mut self, fade_length: PosFloat, fade_type: FadeType, )
main,
to zero volume, using the given fading curve, over the given time
period (in seconds). When the fade is complete, the MixControl will be
removed from existence rather than simply zeroed; future commands to
“prefixed” and “all” will not resuscitate it (unless it is the target
of a future, specific command). Read moreSource§fn kill_mix_control(&mut self, control_name: CompactString)
fn kill_mix_control(&mut self, control_name: CompactString)
Source§fn kill_prefixed_mix_controls(&mut self, control_prefix: CompactString)
fn kill_prefixed_mix_controls(&mut self, control_prefix: CompactString)
Source§fn kill_all_mix_controls(&mut self)
fn kill_all_mix_controls(&mut self)
main, as if you yanked an audio
cable. Read moreSource§fn kill_all_mix_controls_except_main(&mut self)
fn kill_all_mix_controls_except_main(&mut self)
main, as if you yanked an audio
cable. Read moreSource§fn start_flow(
&mut self,
flow_name: CompactString,
target_volume: PosFloat,
fade_length: PosFloat,
fade_type: FadeType,
)
fn start_flow( &mut self, flow_name: CompactString, target_volume: PosFloat, fade_length: PosFloat, fade_type: FadeType, )
fade_flow_to. Read more