Skip to main content

Volume

Struct Volume 

Source
pub struct Volume { /* private fields */ }
Expand description

How loud a note is: music21’s volume.Volume.

Implementations§

Source§

impl Volume

Source

pub fn new() -> Self

A volume with no velocity of its own.

Source

pub fn merge_attributes(&mut self, other: &Volume)

Takes everything another volume says, the velocity and whether it is relative: music21’s mergeAttributes.

Source

pub fn from_velocity(velocity: IntegerType) -> Self

A volume at a MIDI velocity, 0 to 127, clamped to that range.

Source

pub fn from_velocity_scalar(scalar: FloatType) -> Result<Self>

A volume at a scalar between 0 and 1, clamped to that range.

Source

pub fn velocity(&self) -> Option<IntegerType>

The MIDI velocity, 0 to 127, or None when none was set.

Source

pub fn set_velocity(&mut self, velocity: Option<IntegerType>)

Sets the MIDI velocity, clamped to 0 through 127, or clears it.

Source

pub fn velocity_scalar(&self) -> Option<FloatType>

The velocity as a scalar between 0 and 1, or None when none was set.

Source

pub fn set_velocity_scalar(&mut self, scalar: Option<FloatType>) -> Result<()>

Sets the velocity from a scalar, clamped to 0 through 1, or clears it. A value that is not a number is an error, as in music21.

Source

pub fn velocity_is_relative(&self) -> bool

Whether the velocity shifts the dynamics around it (music21’s default) or fixes the loudness on its own, as a velocity read from a MIDI file does.

Source

pub fn set_velocity_is_relative(&mut self, relative: bool)

Sets whether the velocity is relative to its context.

Source

pub fn has_velocity_information(&self) -> bool

Whether a velocity was ever set: music21’s hasVolumeInformation on the note that owns it.

Source

pub fn realized(&self) -> FloatType

The loudness this volume comes to on its own, between 0 and 1: music21’s realized with no dynamic or articulation context.

Source

pub fn realized_with( &self, dynamic_scalar: Option<FloatType>, articulation_shift: FloatType, base_level: FloatType, clip: bool, ) -> FloatType

The loudness this volume comes to against the dynamic in force and whatever the articulations add: music21’s getRealized, with the context search it would do through a stream replaced by its answers.

A relative velocity doubles the scalar range, so 0.5 leaves the base level alone and 0.7 raises it; an absolute one decides the answer by itself. The dynamic scales; an articulation shifts, which is why an accent on a note nobody has marked lifts it rather than doubling it. clip holds the result inside 0 to 1.

Source

pub fn realized_without_velocity( &self, dynamic_scalar: Option<FloatType>, articulation_shift: FloatType, base_level: FloatType, clip: bool, ) -> FloatType

Volume::realized_with leaving this volume’s velocity out: music21’s getRealized(useVelocity=False). The base level stands in for the velocity, with no shift for its being unset, and the dynamic and the articulations then act on it as they would.

Source

pub fn realized_dynamic(&self) -> &'static str

The realized loudness as one of music21’s dynamic marks, ppp through fff: dynamics.dynamicStrFromDecimal of the realized value.

Source

pub fn realized_str(&self) -> String

The realized loudness written out to two places, which is what music21’s getRealizedStr and cachedRealizedStr answer.

Trait Implementations§

Source§

impl Clone for Volume

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Volume

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Volume

Source§

fn default() -> Self

A volume with no velocity set, which reads as music21’s default loudness rather than as silence.

Source§

impl<'de> Deserialize<'de> for Volume

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Volume

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

music21’s repr body, realized=0.71.

music21 writes round(self.realized, 2) into an f-string, so Python’s float formatting drops a trailing zero the way {:.2} does not: half velocity reads realized=0.5, not realized=0.50.

Source§

impl PartialEq for Volume

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Volume

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Volume

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.