[][src]Struct libatm::midi_event::MIDIChannelVoiceMessage

pub struct MIDIChannelVoiceMessage {
    pub delta_time: u8,
    pub status: u8,
    pub note: u8,
    pub velocity: u8,
}

MIDI channel voice message

MIDI supports two main types of messages: Channel and System. Channel messages are tied to a specific MIDI channel, whereas System messages are not (and thus don't contain a channel number). This library only supports channel messages, and more specifically the NoteOn and NoteOff channel voice messages, which actually produce sounds. For a detailed explanation of MIDI messages, see appendix 1.1 of the document here: https://www.cs.cmu.edu/~music/cmsip/readings/Standard-MIDI-file-format-updated.pdf.

Fields

delta_time: u8status: u8note: u8velocity: u8

Methods

impl MIDIChannelVoiceMessage[src]

pub fn new(
    delta_time: u8,
    note: &MIDINote,
    velocity: u8,
    status: MIDIStatus,
    channel: u8
) -> MIDIChannelVoiceMessage
[src]

Create new MIDIChannelVoiceMessage

Arguments

  • delta_time: time delta since last MIDI channel message
  • note: MIDINote to play
  • velocity: velocity with which to play the note
  • status: MIDIStatus bits of the message
  • channel: channel on which to play the message

Examples

// Create Middle C note and two MIDI events, one to "press" the key and
// one to "release" they key after 5 ticks.
let note = libatm::MIDINote::new(libatm::MIDINoteType::C, 4);
let note_on_event = libatm::MIDIChannelVoiceMessage::new(0, &note, 0x64, libatm::MIDIStatus::NoteOn, 0);
let note_off_event = libatm::MIDIChannelVoiceMessage::new(5, &note, 0, libatm::MIDIStatus::RunningStatus, 0);

Notes

  • The meaning of delta_time is determined by the division value present in the MIDIHeader.
  • A NoteOn event with a velocity of 0 is equivalent to a NoteOff event. This library heavily exploits this feature, as well as running status, to produce the smallest possible MIDI files.
  • If the note type is MIDINoteType::Rest then the velocity will automatically be set to 0 (equivalent to a NoteOff event).

pub fn write_buffer<T>(&self, target: &mut T) -> Result<()> where
    T: WriteBytesExt
[src]

Write MIDI channel message to buffer

Arguments

  • target: buffer to write to

Examples

use byteorder::WriteBytesExt;

// Target buffer
let mut buffer = std::io::BufWriter::new(Vec::new());
// Middle C
let note = libatm::MIDINote::new(libatm::MIDINoteType::C, 4);
// Play for 5 ticks
let note_on_event = libatm::MIDIChannelVoiceMessage::new(0, &note, 0x64, libatm::MIDIStatus::NoteOn, 0);
let note_off_event = libatm::MIDIChannelVoiceMessage::new(5, &note, 0, libatm::MIDIStatus::RunningStatus, 0);
// Write notes to buffer
note_on_event.write_buffer(&mut buffer).unwrap();
note_off_event.write_buffer(&mut buffer).unwrap();

Trait Implementations

impl Clone for MIDIChannelVoiceMessage[src]

impl Copy for MIDIChannelVoiceMessage[src]

impl PartialEq<MIDIChannelVoiceMessage> for MIDIChannelVoiceMessage[src]

impl Debug for MIDIChannelVoiceMessage[src]

impl StructuralPartialEq for MIDIChannelVoiceMessage[src]

Auto Trait Implementations

impl Send for MIDIChannelVoiceMessage

impl Sync for MIDIChannelVoiceMessage

impl Unpin for MIDIChannelVoiceMessage

impl UnwindSafe for MIDIChannelVoiceMessage

impl RefUnwindSafe for MIDIChannelVoiceMessage

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]