[][src]Struct libatm::midi_file::MIDIFile

pub struct MIDIFile {
    pub sequence: MIDINoteVec,
    pub format: MIDIFormat,
    pub tracks: u16,
    pub division: u16,
}

MIDI file representation

MIDI files can be complex, allowing for any number of tracks with different notes and instruments playing simultaneously. This library was created for the express purpose of brute-forcing melodies, and thus only supports a subset of the official MIDI standard. More specifically, this implementation is optimized to create the smallest possible single track MIDI files.

Fields

sequence: MIDINoteVec

Sequence of notes to generate the track chunk from

format: MIDIFormat

Format specification (should always be MIDIFormat::0)

tracks: u16

Number of tracks in MIDI file (should always be 1)

division: u16

Number of ticks to represent a quarter-note (recommended to use 1)

Implementations

impl MIDIFile[src]

pub fn new(
    sequence: MIDINoteVec,
    format: MIDIFormat,
    tracks: u16,
    division: u16
) -> MIDIFile
[src]

Create new MIDIFile

Examples

let mfile = libatm::MIDIFile::new(
    "C:4,CSharp:8,D:5,DSharp:3".parse::<libatm::MIDINoteVec>().unwrap(),
    libatm::MIDIFormat::Format0,
    1,
    1,
);
assert_eq!("601097451", mfile.gen_hash());

pub fn gen_hash(&self) -> String[src]

Generate unique hash for this file's MIDINote sequence

This hash function simply concatenates the sequential integer representation of the file's sequence of MIDINote. By this definition, no two non-identical sequences can have the same hash. The primary intended purpose of this function is to allow for O(1) lookups by note sequence once a file has been written to disk.

pub fn gen_header(&self) -> MIDIHeader[src]

Generate header chunk (see: MIDIHeader)

pub fn gen_track_size(&self) -> u32[src]

Generate the size of this track chunk header in bytes (on disk)

pub fn gen_track_header(&self) -> MIDITrackHeader[src]

Generate track chunk header (see: MIDITrackHeader)

pub fn gen_track(&self) -> Vec<MIDIChannelVoiceMessage>[src]

Generate track data (see: MIDIChannelVoiceMessage)

pub fn gen_size(&self) -> u32[src]

Generate the size of this MIDI file in bytes (on disk)

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

Write MIDI file to buffer

pub fn write_file<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]

Write MIDI file to path on disk

pub fn gen_file(&self) -> Result<Vec<u8>>[src]

Generate buffer containing entire MIDI file

Trait Implementations

impl Clone for MIDIFile[src]

impl Debug for MIDIFile[src]

Auto Trait Implementations

impl RefUnwindSafe for MIDIFile

impl Send for MIDIFile

impl Sync for MIDIFile

impl Unpin for MIDIFile

impl UnwindSafe for MIDIFile

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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.