All Projects → cagpie → PicoAudio.js

cagpie / PicoAudio.js

Licence: MIT License
A JavaScript library for playing MIDI (Standard MIDI File) on Web.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to PicoAudio.js

midi
An Observable based library for the use of Web MIDI API with Angular
Stars: ✭ 35 (+25%)
Mutual labels:  midi, webmidi, webaudio, webmidi-api
musicplayer-api
Simple wrapper around Web Audio API providing gapless playback
Stars: ✭ 16 (-42.86%)
Mutual labels:  music-player, webaudio, webaudio-api
Scribbletune
Create music with JavaScript
Stars: ✭ 3,509 (+12432.14%)
Mutual labels:  midi, webmidi, webaudio
websynth
Web Synthesizer From Space
Stars: ✭ 16 (-42.86%)
Mutual labels:  webaudio, webaudio-api
abletonpush
A library for working with the Ableton Push in the browser
Stars: ✭ 47 (+67.86%)
Mutual labels:  webmidi, webaudio
ptweb
An in-browser music player and visualizer for songs made in pxtone!
Stars: ✭ 23 (-17.86%)
Mutual labels:  webaudio, chiptune
Shape-Your-Music
A web application for drawing music.
Stars: ✭ 106 (+278.57%)
Mutual labels:  midi, webaudio
X-Piano
Now you can make your own piano!
Stars: ✭ 13 (-53.57%)
Mutual labels:  webaudio, webaudio-api
OpenDeck
Software and hardware platform for simpler building of MIDI controllers with support for DMX.
Stars: ✭ 438 (+1464.29%)
Mutual labels:  midi, webmidi
webmscore
MuseScore's core library (libmscore) in WebAssembly! Read mscz data, and generate audio/MIDI/MusicXML/SVG/PNG/PDF sheets right in browsers.
Stars: ✭ 91 (+225%)
Mutual labels:  midi, webaudio
LabMidi
Midi IN and OUT. Standard midi file parser and player. Midi Softsynth implementation.
Stars: ✭ 38 (+35.71%)
Mutual labels:  music-player, midi
pacer-editor
Web editor for the Nektar Pacer MIDI controler
Stars: ✭ 16 (-42.86%)
Mutual labels:  midi, webmidi
jamhub
low-latency jamming space for musicians
Stars: ✭ 29 (+3.57%)
Mutual labels:  midi, webaudio
microfreak-reader
An application to read and display the presets stored in the Arturia MicroFreak memory.
Stars: ✭ 32 (+14.29%)
Mutual labels:  midi, webmidi
purescript-school-of-music
Port of the Haskell School of Music to Purescript
Stars: ✭ 21 (-25%)
Mutual labels:  music-player, midi
BS2-Web
Novation Bass Station II Web interface
Stars: ✭ 34 (+21.43%)
Mutual labels:  midi, webmidi
ANMP
multi-channel loopable video game music player for nerds and audiophiles
Stars: ✭ 16 (-42.86%)
Mutual labels:  music-player, midi
webaudio-synth
WebAudio Polyphonic Synthesizer
Stars: ✭ 83 (+196.43%)
Mutual labels:  midi, webaudio
wui
Collection of GUI widgets for the web
Stars: ✭ 44 (+57.14%)
Mutual labels:  midi, webmidi
learn-push2-with-svelte
Learn chords, scales, and music theory on the Push 2, right inside your web browser!
Stars: ✭ 37 (+32.14%)
Mutual labels:  midi, webmidi

PicoAudio.js

PicoAudio.jsについて

Web上でMIDI(Standard MIDI File=SMF)を再生するためのJavaScriptライブラリです。
SMF形式のバイナリのパースや、Web Audio API を用いた楽曲の再生ができます。

Web Audio API から提供される数種の音源を組み合わせて、8bitサウンドで演奏を行います。
また、別途音源の準備をする必要がなく、Webと音楽を組み合わせた開発がすぐに始められます!

A JavaScript library for playing MIDI (Standard MIDI File = SMF) on Web.
You can parse SMF Files and play music using Web Audio API.

Play with 8-bit sound by combining several types of sound sources provided by Web Audio API.
There is no need to prepare a sound source, and development that combines the Web and Music can be started immediately!

主な機能

  • MIDIファイル(SMF)のパース
  • パースしたデータの再生
  • 再生時のnoteOn/noteOffイベント受け取り など

利用されているプロダクト

サンプル

導入方法

Browser

<script src="https://unpkg.com/picoaudio/dist/browser/PicoAudio.js"></script>
または、
<script src="https://unpkg.com/picoaudio/dist/browser/PicoAudio.min.js"></script>

※ グローバル変数に PicoAudio が定義されます

Module

$ npm install picoaudio

https://www.npmjs.com/package/picoaudio (pico-audio-js has deprecated)

はじめ方

初期化

const picoAudio = new PicoAudio();
picoAudio.init();

再生

// Standard MIDI Fileの準備
const file = /* FileReaderやFetchなどで取得 */
const smfData = new Uint8Array(file);

// SMF形式のバイナリのパースを行う
const parsedData = picoAudio.parseSMF(smfData);

// パースしたデータをセット
picoAudio.setData(parsedData);

// 再生
picoAudio.play();

PicoAudio.play メソッドは、ユーザのジェスチャーイベントから呼び出す必要がある場合があります (参考)

停止

// 一時停止
picoAudio.pause();

API

Main Functions

PicoAudio.init

// PicoAudioインスタンスの生成
new PicoAudio({
  debug: boolean, // デバッグON/OFF
  audioContext: AudioContext, // 生成済みのAudioContextを再利用
  picoAudio: PicoAudio, // 生成済みのPicoAudioインスタンスを再利用
}): PicoAudio

※ 細かいパラメータも設定可能 (参考)

PicoAudio.parseSMF

// SMFファイルをパースし、PicoAudioで再生できる形式にする
// ピアノロールの描画を行いたい場合などに、ParsedSMFが利用できる
PicoAudio.parseSMF(smfFile: Uint8Array): ParsedSMF

PicoAudio.setData

// パースされたデータをセットする
PicoAudio.setData(parsedSMF: ParsedSMF): void

PicoAudio.play

// セットされているデータで再生する
PicoAudio.play(isLoop: boolean): void

PicoAudio.pause

// 楽曲の一時停止
PicoAudio.pause(): void

PicoAudio.initStatus

// 再生状態の初期化
PicoAudio.initStatus(): void

PicoAudio.setStartTime

// 再生開始位置の設定
PicoAudio.setStartTime(offseTime: number) :void

ステータスのSetter/Getter

// 全体音量の設定
PicoAudio.getMasterVolume(): number
PicoAudio.setMasterVolume(volume: number): void

// リバーブの設定
PicoAudio.isReverb(): boolean
PicoAudio.setReverb(enable: boolean): void
PicoAudio.getReverbVolume(): number
PicoAudio.setReverbVolume(volume: number): void

// コーラスの設定
PicoAudio.isChorus(): boolean
PicoAudio.setChorus(enable: boolean): void
PicoAudio.getChorusVolume(): number
PicoAudio.setChorusVolume(volume: number): void

// チャンネルの音色情報や音量の設定
PicoAudio.initChannels(): void
PicoAudio.getChannels(): Array
PicoAudio.setChannels(channels: Array): void

// ループの設定
PicoAudio.isLoop(): boolean
PicoAudio.setLoop(enable: boolean): void

// Web MIDI APIの設定
PicoAudio.isWebMIDI(): boolean
PicoAudio.setWebMIDI(enable: boolean): void

// Control Change 111 のループの設定
PicoAudio.isCC111(): boolean
PicoAudio.setCC111(enable: boolean): void

Event周辺

PicoAudio.addEventListener

// イベントリスナを登録
PicoAudio.addEventListener(
  type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>,
  listener: Function
): void
PicoAudio.addEventListener (noteOn)
// 音の開始イベントのリスナ登録ができる
// 発音される音のタイミングや高さ、強さなどが取得できる
PicoAudio.addEventListener(
  type: 'noteOn',
  listener: (event: NoteEvent) => void
): void

type NoteEvent = {
  channel: number, // チャンネル(0-15)
  instrument: number, // 楽器の種類(0-127)

  start: number, // 音の始まりのタイミング(tick=SMF時間)
  stop: number, // 音の終わりのタイミング(tick)
  startTime: number, // 音の始まりのタイミング(秒数)
  stopTime: number, // 音の終わりのタイミング(秒数)

  velocity: number, // ベロシティ(0-1)
  pitch: number, // 音の高さ(0-127)

  // CCパラメータ
  pan: CCEvent[],
  pitchBend: CCEvent[],
  expression: CCEvent[],
  modulation: CCEvent[],
  chorus: CCEvent[],
  reberb: CCEvent[],
}

type CCEvent = {
  timing: number, // タイミング(tick)
  time: number, // タイミング(秒数)
  value: number // 値(0-127)
}
PicoAudio.addEventListener (noteOff)
// 音の終了イベントのリスナ登録ができる
PicoAudio.addEventListener(
  type: 'noteOff',
  listener: (event: NoteEvent) => void
): void

removeEventListener

// 指定のイベントリスナを解除
PicoAudio.removeEventListener(
  type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>,
  listener: Function
): void

removeAllEventListener

// 指定typeのイベントリスナをすべて解除
PicoAudio.removeAllEventListener(
  type: <'play' | 'pause' | 'noteOn' | 'noteOff' | 'songEnd'>
): void

SMFパース周辺

parsed SMF

// 準備中
変換関数
PicoAudio.getTime
// tick から 時間に変換 (テンポも考慮される)
PicoAudio.getTime(tick: number): number
PicoAudio.getTiming
// 時間からtickに変換
PicoAudio.getTiming(time: number): number

License

Code released under the MIT License

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].