Struct knyst::envelope::EnvelopeGen
source · pub struct EnvelopeGen {
pub start_value: Sample,
pub playing: bool,
/* private fields */
}
Expand description
An envelope Gen. Must be started by calling EnvelopeGen::start
since that
will initialise it based on the settings of its segments. If you want to use
it offline, it can be turned into an iterator by calling EnvelopeGen::iter_mut
.
Fields§
§start_value: Sample
§playing: bool
Implementations§
source§impl EnvelopeGen
impl EnvelopeGen
sourcepub fn adsr(
attack_time: Sample,
decay_time: Sample,
sustain_level: Sample,
release_time: Sample
) -> Self
pub fn adsr( attack_time: Sample, decay_time: Sample, sustain_level: Sample, release_time: Sample ) -> Self
Convenience method for an ADSR envelope
sourcepub fn sustain(self, sustain: SustainMode) -> Self
pub fn sustain(self, sustain: SustainMode) -> Self
Set the SustainMode
sourcepub fn stop_action(self, stop_action: StopAction) -> Self
pub fn stop_action(self, stop_action: StopAction) -> Self
Set the StopAction
sourcepub fn set_points(&mut self, points: Vec<(Sample, Sample)>)
pub fn set_points(&mut self, points: Vec<(Sample, Sample)>)
Set the points of the envelope. Points are in the format (next_leve, time_to_reach_that_level_in_seconds)
sourcepub fn curves(self, curves: Vec<Curve>) -> Self
pub fn curves(self, curves: Vec<Curve>) -> Self
If the curves are differently many from the points, fill with Curve::Linear for the later segments.
pub fn get_point(&mut self, index: usize) -> (Sample, Sample)
sourcepub fn update_from_envelope(&mut self, other: &EnvelopeGen)
pub fn update_from_envelope(&mut self, other: &EnvelopeGen)
Updates the values of the this Envelope to match those of the other Envelope if it can be done without allocation. The Envelopes are assumed to match.
sourcepub fn restart_from_current(&mut self)
pub fn restart_from_current(&mut self)
Initialises the envelope based on the current value and the first point
sourcepub fn release(&mut self)
pub fn release(&mut self)
Releases the envelope if it is sustaining or immediately fades out if it is not.
sourcepub fn fade_out(&mut self)
pub fn fade_out(&mut self)
Immediately fade the output to 0.0. This is called if
EnvelopeGen::release
is called on a non sustaining and non looping
envelope.
sourcepub fn set_duration(&mut self, duration: Sample, index: usize)
pub fn set_duration(&mut self, duration: Sample, index: usize)
Set the duration of a segment in seconds (the duration to reach the value with the same index). Will not affect the currently playing segment.
sourcepub fn next_sample(&mut self) -> Sample
pub fn next_sample(&mut self) -> Sample
Get the next sample of the envelope
sourcepub fn iter_mut(&mut self) -> EnvelopeIterator<'_> ⓘ
pub fn iter_mut(&mut self) -> EnvelopeIterator<'_> ⓘ
Evaluate Self
as an iterator. Evaluating the envelope means changing
the state which is why it is mut.
source§impl EnvelopeGen
impl EnvelopeGen
sourcepub fn new(
start_value: Sample,
points: Vec<(Sample, Sample)>,
sustain: SustainMode,
stop_action: StopAction
) -> Self
pub fn new( start_value: Sample, points: Vec<(Sample, Sample)>, sustain: SustainMode, stop_action: StopAction ) -> Self
Create a new Envelope. points are in the format (level, duration) where the duration is given in seconds, and later converted to samples internally.
source§impl EnvelopeGen
impl EnvelopeGen
sourcepub fn upload(self) -> Handle<EnvelopeGenHandle>
pub fn upload(self) -> Handle<EnvelopeGenHandle>
Upload the Gen to the currently selected Graph and return a handle
Trait Implementations§
source§impl Clone for EnvelopeGen
impl Clone for EnvelopeGen
source§fn clone(&self) -> EnvelopeGen
fn clone(&self) -> EnvelopeGen
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EnvelopeGen
impl Debug for EnvelopeGen
source§impl Gen for EnvelopeGen
impl Gen for EnvelopeGen
source§fn process(
&mut self,
ctx: GenContext<'_, '_>,
resources: &mut Resources
) -> GenState
fn process( &mut self, ctx: GenContext<'_, '_>, resources: &mut Resources ) -> GenState
source§fn num_inputs(&self) -> usize
fn num_inputs(&self) -> usize
Gen
takes. Determines how big the input buffer is.source§fn num_outputs(&self) -> usize
fn num_outputs(&self) -> usize
Gen
produces. Determines how big the output buffer is.source§fn input_desc(&self, input: usize) -> &'static str
fn input_desc(&self, input: usize) -> &'static str
Connection
API.source§fn output_desc(&self, output: usize) -> &'static str
fn output_desc(&self, output: usize) -> &'static str
Connection
API.Auto Trait Implementations§
impl RefUnwindSafe for EnvelopeGen
impl Send for EnvelopeGen
impl Sync for EnvelopeGen
impl Unpin for EnvelopeGen
impl UnwindSafe for EnvelopeGen
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.