All Projects → acknak → ghakuf

acknak / ghakuf

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
A Rust library for parsing/building SMF (Standard MIDI File).

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to ghakuf

CaptCC
A tiny C compiler written purely in JavaScript.
Stars: ✭ 175 (+483.33%)
Mutual labels:  parsing
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (-13.33%)
Mutual labels:  rust-library
tentacle
A multiplexed p2p network framework that supports custom protocols
Stars: ✭ 41 (+36.67%)
Mutual labels:  rust-library
postcss-jsx
PostCSS syntax for parsing CSS in JS literals
Stars: ✭ 73 (+143.33%)
Mutual labels:  parsing
arangors
Easy to use rust driver for arangoDB
Stars: ✭ 120 (+300%)
Mutual labels:  rust-library
masci-tools
Tools, utility, parsers useful in daily material science work
Stars: ✭ 18 (-40%)
Mutual labels:  parsing
autumn
A Java parser combinator library written with an unmatched feature set.
Stars: ✭ 112 (+273.33%)
Mutual labels:  parsing
colorful
Make your terminal output colorful.
Stars: ✭ 43 (+43.33%)
Mutual labels:  rust-library
teensy-midi-looper
teensy midi loop recorder
Stars: ✭ 30 (+0%)
Mutual labels:  smf
twitter-stream-rs
A Rust library for listening on Twitter Streaming API.
Stars: ✭ 66 (+120%)
Mutual labels:  rust-library
yellowpages-scraper
Yellowpages.com Web Scraper written in Python and LXML to extract business details available based on a particular category and location.
Stars: ✭ 56 (+86.67%)
Mutual labels:  parsing
Awesome-Rust-MachineLearning
This repository is a list of machine learning libraries written in Rust. It's a compilation of GitHub repositories, blogs, books, movies, discussions, papers, etc. 🦀
Stars: ✭ 1,110 (+3600%)
Mutual labels:  rust-library
vfin
🦈 GUI framework agnostic virtual DOM library
Stars: ✭ 17 (-43.33%)
Mutual labels:  rust-library
hidapi-rs
Rust bindings for the hidapi C library
Stars: ✭ 103 (+243.33%)
Mutual labels:  rust-library
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+230%)
Mutual labels:  rust-library
DotGrok
Parse text with pattern. Inspired by grok filter.
Stars: ✭ 26 (-13.33%)
Mutual labels:  parsing
Nebuchadnezzar
High Performance Key-Value Store
Stars: ✭ 49 (+63.33%)
Mutual labels:  rust-library
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+346.67%)
Mutual labels:  parsing
NFlags
Simple yet powerfull library to made parsing CLI arguments easy. Library also allow to print usage help "out of box".
Stars: ✭ 44 (+46.67%)
Mutual labels:  parsing
contour-rs
Contour polygon creation in Rust (using marching squares algorithm)
Stars: ✭ 33 (+10%)
Mutual labels:  rust-library

ghakuf

A Rust library for parsing/building SMF (Standard MIDI File).

Build Status Crates.io

Examples

ghakuf has parse module and build module separatory.

Perser

ghakuf's parser is made by Event-driven online algorithm. You must prepare original handler implementing Handler trait to catch SMF messages. Any number of handlers you can add for parser if you want.

use ghakuf::messages::*;
use ghakuf::reader::*;
use std::path;

let path = path::Path::new("test.mid");
let mut handler = HogeHandler{};
let mut reader = Reader::new(
    &mut handler,
    &path,
).unwrap();
let _ = reader.read();

struct HogeHandler {}
impl Handler for HogeHandler {
    fn header(&mut self, format: u16, track: u16, time_base: u16) {
      // Something
    }
    fn meta_event(&mut self, delta_time: u32, event: &MetaEvent, data: &Vec<u8>) {
      // you
    }
    fn midi_event(&mut self, delta_time: u32, event: &MidiEvent) {
      // want
    }
    fn sys_ex_event(&mut self, delta_time: u32, event: &SysExEvent, data: &Vec<u8>) {
      // to
    }
    fn track_change(&mut self) {
      // do
    }
}

Builder

ghakuf build SMF by Message enums. Message enum consists of MetaEvent, MidiEvent, SysExEvent, and TrackChange. You can use running status if you want. At track change, you should use not only MetaEvent::EndOfTrack message, but also TrackChange message.

use ghakuf::messages::*;
use ghakuf::writer::*;
use std::path;

let tempo: u32 = 60 * 1000000 / 102; //bpm:102
let write_messages: Vec<Message> = vec![
    Message::MetaEvent {
        delta_time: 0,
        event: MetaEvent::SetTempo,
        data: [(tempo >> 16) as u8, (tempo >> 8) as u8, tempo as u8].to_vec(),
    },
    Message::MetaEvent {
        delta_time: 0,
        event: MetaEvent::EndOfTrack,
        data: Vec::new(),
    },
    Message::TrackChange,
    Message::MidiEvent {
        delta_time: 0,
        event: MidiEvent::NoteOn {
            ch: 0,
            note: 0x3c,
            velocity: 0x7f,
        },
    },
    Message::MidiEvent {
        delta_time: 192,
        event: MidiEvent::NoteOn {
            ch: 0,
            note: 0x40,
            velocity: 0,
        },
    },
    Message::MetaEvent {
        delta_time: 0,
        event: MetaEvent::EndOfTrack,
        data: Vec::new(),
    }
];
let path = path::Path::new("examples/example.mid");
let mut writer = Writer::new();
writer.running_status(true);
for message in &write_messages {
    writer.push(&message);
}
let _ = writer.write(&path);

Supported SMF Event

You can use three type events. In Message enum, these events have delta time and data.

Meta Event

  • SequenceNumber
  • TextEvent
  • CopyrightNotice
  • SequenceOrTrackName
  • InstrumentName
  • Lyric
  • Marker
  • CuePoint
  • MIDIChannelPrefix
  • EndOfTrack
  • SetTempo
  • SMTPEOffset
  • TimeSignature
  • KeySignature
  • SequencerSpecificMetaEvent

MIDI Event

  • NoteOff { ch: u8, note: u8, velocity: u8 }
  • NoteOn { ch: u8, note: u8, velocity: u8 }
  • PolyphonicKeyPressure { ch: u8, note: u8, velocity: u8 }
  • ControlChange { ch: u8, control: u8, data: u8 }
  • ProgramChange { ch: u8, program: u8 }
  • ChannelPressure { ch: u8, pressure: u8 }
  • PitchBendChange { ch: u8, data: i16 }

System Exclusive Event

  • (F0 event)
  • (F7 event)

License

ghakuf is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, and LICENSE-MIT for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].