Note

Struct Note 

Source
pub struct Note(pub u8);
Expand description

A musical note, corresponding to a specific frequency in 12 tone equal temperament space.

Tuple Fields§

§0: u8

Implementations§

Source§

impl Note

Source

pub fn pitch_class(&self) -> PitchClass

Returns the note’s PitchClass.

use redact_composer_musical::{Note, NoteName::C, PitchClass};

assert_eq!(Note::from((C, 4)).pitch_class(), PitchClass(0));
Source

pub fn octave(&self) -> i8

Returns the octave number of this note:

use redact_composer_musical::{Note, NoteName::{B, C}};

assert_eq!(Note::from((C, 0)).octave(), 0);
assert_eq!(Note::from((B, 5)).octave(), 5);
Source

pub fn interval_with(&self, other_note: &Note) -> Interval

Returns the interval between this note and another.

use redact_composer_musical::{Interval, Note, NoteName::C};

assert_eq!(Note::from((C, 3)).interval_with(&Note::from((C, 4))), Interval::Octave);
Source§

impl Note

Source

pub fn play(&self, velocity: u8) -> PlayNote

Creates a PlayNote element from this note, which can then be used as a Segment.

use redact_composer_core::{elements::PlayNote, timing::Timing, IntoSegment};
use redact_composer_musical::{Note, NoteName::C};

let expected_play_note = PlayNote { note: 60, velocity: 100};
let play_note = Note::from((C, 4)).play(100);
assert_eq!(play_note, expected_play_note);

let segment = play_note.into_segment(0..480);
assert_eq!(segment.element_as::<PlayNote>(), Some(&expected_play_note));
assert_eq!(segment.timing, Timing::from(0..480));

Trait Implementations§

Source§

impl Add<Interval> for Note

Source§

fn add(self, rhs: Interval) -> <Note as Add<Interval>>::Output

Adds an interval to this note, resulting in another note.

use redact_composer_musical::{Interval as I, Note, NoteName::{C, G}};

let c3 = Note::from((C, 4));
assert_eq!(c3, Note(60));
assert_eq!(c3 + I::P5, Note::from((G, 4)));
Source§

type Output = Note

The resulting type after applying the + operator.
Source§

impl AddAssign<Interval> for Note

Source§

fn add_assign(&mut self, rhs: Interval)

Performs the += operation. Read more
Source§

impl Clone for Note

Source§

fn clone(&self) -> Note

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Note

Source§

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

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

impl<'de> Deserialize<'de> for Note

Source§

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

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

impl Element for Note

Source§

fn wrapped_element(&self) -> Option<&(dyn Element + 'static)>

None.
Source§

impl From<(NoteName, i8)> for Note

Source§

fn from(value: (NoteName, i8)) -> Note

use redact_composer_musical::{Note, NoteName::C};

assert_eq!(Note::from((C, 4)), Note(60));
Source§

impl From<(PitchClass, i8)> for Note

Source§

fn from(value: (PitchClass, i8)) -> Note

use redact_composer_musical::{Note, NoteName::C, PitchClass};

let c3 = Note::from((PitchClass(0), 4));
assert_eq!(c3, Note(60));
Source§

impl From<Note> for PitchClass

Source§

fn from(value: Note) -> PitchClass

Converts to this type from the input type.
Source§

impl Hash for Note

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Note

Source§

fn cmp(&self, other: &Note) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<(NoteName, i8)> for Note

Source§

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

use redact_composer_musical::{Note, NoteName::*};
assert_eq!(Note(60), (C, 4));
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<PitchClass> for Note

Source§

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

use redact_composer_musical::{Note, NoteName::C, PitchClass};

assert!(Note::from((C, 3)) == PitchClass::from(C));
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Note

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Note

Source§

fn partial_cmp(&self, other: &Note) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Note

Source§

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

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

impl Sub<Interval> for Note

Source§

fn sub(self, rhs: Interval) -> <Note as Sub<Interval>>::Output

Subtracts an interval from this note, resulting in another note.

use redact_composer_musical::{Interval as I, Note, NoteName::{C, G}};

let c3 = Note::from((C, 3));
assert_eq!(c3 - I::P4, Note::from((G, 2)));
Source§

type Output = Note

The resulting type after applying the - operator.
Source§

impl SubAssign<Interval> for Note

Source§

fn sub_assign(&mut self, rhs: Interval)

Performs the -= operation. Read more
Source§

impl Copy for Note

Source§

impl Eq for Note

Source§

impl StructuralPartialEq for Note

Auto Trait Implementations§

§

impl Freeze for Note

§

impl RefUnwindSafe for Note

§

impl Send for Note

§

impl Sync for Note

§

impl Unpin for Note

§

impl UnwindSafe for Note

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> AsAny for T
where T: Element,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts this to a [&dyn Any].
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> 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> IntoSegment for T
where T: Element,

Source§

fn into_segment(self, timing: impl Into<Timing>) -> Segment

Creates a Segment from this element, spanning the given time range.

Source§

fn over(self, timing: impl Into<Timing>) -> Segment

Creates a Segment from this element, spanning the given time range.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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