Skip to main content

Crate pikopiko

Crate pikopiko 

Source
Expand description

§pikopiko

MMLテキストを解析してチップチューンを鳴らす pure Rust ライブラリ。 コアはオーディオ出力やスレッドを知らない。音を出すには、利用側で Player::render をオーディオコールバックから呼ぶ。

use std::sync::Arc;

let song = pikopiko::compile("A t150 l8 o4 cdefgab>c").expect("MMLに誤りがある");
let mut player = pikopiko::Player::new(Arc::new(song), 48_000);
let mut buf = [[0.0f32; 2]; 512];
player.render(&mut buf); // オーディオコールバックの中で呼ぶ

文法は SPEC(docs/spec.md)、使い方は取扱説明書(docs/guide/)を参照。

§Overview (English)

pikopiko is a pure Rust library that parses MML (Music Macro Language) text and plays chiptune and synth music. The core knows nothing about audio output or threads: to make sound, call Player::render from your audio callback, as in the example above.

  • The grammar is in SPEC_EN (docs/en/spec.md; SPEC is the Japanese original).
  • The user guide is in English at docs/en/guide/.
  • Diagnostics, synth descriptions and the CLI / MCP messages are available in English and Japanese (see lang).
  • The documentation comments of the public API below are written in Japanese. The user guide and the grammar specification are the English entry points.

Re-exports§

pub use compiler::ast::Ast;
pub use compiler::diagnostic::Diagnostic;
pub use compiler::diagnostic::Severity;
pub use compiler::diagnostic::Span;
pub use compiler::dialect::Dialect;
pub use compiler::song::ChordKeys;
pub use compiler::song::Event;
pub use compiler::song::EventKind;
pub use compiler::song::Marker;
pub use compiler::song::Meter;
pub use compiler::song::Song;
pub use compiler::song::SongMeta;
pub use player::voice::SynthVoice;
pub use player::voice::Voice;
pub use player::render_to_vec;
pub use player::render_to_vec_looped;
pub use player::render_to_vec_looped_with;
pub use player::render_to_vec_with;
pub use player::Command;
pub use player::Notice;
pub use player::Player;
pub use player::SfxError;
pub use player::SfxId;
pub use player::TrackActivity;
pub use player::MAX_REGISTERED_SFX;
pub use player::NOTICE_CAPACITY;
pub use report::info::describe;
pub use report::info::describe_with;
pub use report::info::key_name;
pub use report::info::secs_to_ticks;
pub use report::info::ticks_to_secs;
pub use report::info::KeyInfo;
pub use report::info::MarkerInfo;
pub use report::info::SongInfo;
pub use report::info::TrackInfo;
pub use synth::SynthConfig;
pub use synth::SynthSpec;
pub use pikopiko_runtime as runtime;

Modules§

compiler
翻訳(MML のテキスト → 曲)
composer
作曲支援
export
書き出し(曲 → 別の形)
lang
画面の言語の決め方と、画面の文言の口。
language
言語サービスの層:エディタなどの使う側が、編集のたびに MML の色付け・診断・補完・ホバー・ 定義へ移動・ソースの位置と再生位置(tick)の対応を引く口。
player
再生役(曲 → 音)
report
報告(曲を数値と JSON で説明する)
synth
音源。曲が使う音源は #synth 指令で選ぶ(既定は basic)。
text
訳せる文(エラーの文など)の口(pikopiko_runtime::text)。 訳せる文(エラーの文など)の口と、文の表。no_std・ヒープなし。

Macros§

msg
診断の文を作る:msg!("E0301-value", cmd = "v", value = 99, min = 0, max = 15)。 キーは messages の型の名前で、値の名前は型の {$名前} と同じにする。

Structs§

CompileOptions
解析と展開の設定。
NoticeMask
どの通知を受け取るか。ビットの組み合わせ。
SfxChannels
効果音のトラックを、BGM のどのチャンネルに割り当てるか。

Enums§

JumpAt
マーカーへ移動するとき。

Constants§

MAX_LENGTH_NUMBER
音長 n(n 分音符)に書ける最大の数。
MAX_TICK_LENGTH
tick で書く音長(c%120)の最大(表記上の tick。全音符 255 個分)。
NOTATION_SCALE
表記上の tick 1 つあたりの内部の tick 数(= 21)。
NOTATION_WHOLE
MML に書く tick(表記上の tick)の全音符の数。c%120 の 120 はこの単位で、内部の tick は NOTATION_SCALE 倍になる。内部の PPQ を変えても、MML に書く数は変わらない。
PPQ
4分音符あたりのtick数(10080。7 連符・9 連符も整数の tick で表せる)。
SPEC
MML文法仕様(docs/spec.md の全文、日本語)。生成AIにそのまま渡せる。日本語版が正本。
SPEC_EN
MML文法仕様の英語版(docs/en/spec.md の全文)。SPEC の翻訳で、食い違ったら日本語版が正しい。
WHOLE_TICKS
全音符のtick数(= 4 × PPQ = 40320)。音長 n(n 分音符)は、これを割り切れる数でなければならない。

Traits§

Synth
音を作る実体。定義はランタイム層の pikopiko-runtime にある(no_std でも使えるように)。 音を作る実体。オーディオスレッドで呼ばれるので、どのメソッドでも メモリ確保、ロック、I/O、パニックをしてはいけない。

Functions§

compile
解析と展開をまとめて行う。エラーが1つでもあれば、すべての診断(警告を含む)を返す。
compile_with
設定を指定して解析と展開を行う。
compile_with_diagnostics
解析と展開をまとめて行う。エラーがあれば None。警告は診断に含まれる。
is_japanese
言語タグが日本語(ja、ja-JP、ja_JP.UTF-8 など)か。AI に渡す文の言語を選ぶのに使う。
parse
MMLを構文解析する(方言 pikopiko)。エラーがあっても部分的なASTとすべての診断を返す。
parse_with
方言を指定して構文解析する。#include は読めない(E0601)。
parse_with_options
設定(方言、#include の読み込みの口、共有の定義)を指定して構文解析する。
spec_for
言語タグ(en・ja など)に合う文法仕様。日本語なら SPEC、それ以外は SPEC_EN。