Skip to main content

Sequencer

Struct Sequencer 

Source
pub struct Sequencer<'a, const TRACKS: usize = 8> { /* private fields */ }
Expand description

イベント列バイナリを鳴らすシーケンサー。ヒープを使わない。 TRACKS は扱えるトラック数の上限(既定 8)。

Implementations§

Source§

impl<'a, const TRACKS: usize> Sequencer<'a, TRACKS>

Source

pub fn render<C: Synth + ?Sized>(&mut self, synth: &mut C, out: &mut [[f32; 2]])

out を埋める。メモリ確保、ロック、I/O、パニックをしない。

Source

pub fn step<C: Synth + ?Sized>(&mut self, synth: &mut C) -> bool

1 サンプル分だけ進める(イベントを送り、エンベロープと音程エフェクトを進める)。 音源の next は呼ばないので、ほかの曲(効果音など)と同じ音源を鳴らすときに使う。 鳴らすべきサンプルなら true、終わっている(終わった)なら false。 Sequencer::render は、これと音源の next(audible) を 1 サンプルずつ呼ぶのと同じ。

Source§

impl<'a, const TRACKS: usize> Sequencer<'a, TRACKS>

Source

pub fn restart(&mut self)

頭から鳴らし直す(次の render で音源もリセットする)。待っている移動は取り消す。

Source

pub fn set_paused(&mut self, paused: bool)

一時停止する(true)か、続きから鳴らす(false)。一時停止の間は時間を進めず、 render は無音を書き、step は false を返す(音源は呼ばない)。

Source

pub fn is_paused(&self) -> bool

一時停止しているか(Sequencer::set_paused)。

Source

pub fn set_tempo_scale(&mut self, scale_milli: u32)

テンポ倍率(1/1000 単位。1000 が等倍、10〜100000 に丸める)。pikopiko::Player の Command::SetTempoScale と同じ(Player は倍率を 1/1000 に丸めて使う)。

Source

pub fn tempo_scale(&self) -> u32

テンポ倍率(1/1000 単位、Sequencer::set_tempo_scale)。

Source

pub fn seek(&mut self, tick: u64)

指定 tick(Header::ppq の tick)へ移動する。曲の長さより後なら曲の終わりへ。 移動は次の step(render)の初めに行う:音源をリセットし、移動先より前の音色・ パラメータ・テンポ・エンベロープ類の選択を順に送り直す(音は鳴らさない)。 終わった曲でも、移動先が曲の終わりより前なら、そこから鳴らす。 待っている拍・小節での移動は、移った先の次の頭で行う。

Source

pub fn set_transpose(&mut self, semitones: i8)

再生中の移調(半音。−24〜24 に丸める。0 で元の高さ)。pikopiko::Player の Command::SetTranspose と同じ:送った後に始まる音から効き、鳴っている音はそのまま。 音の高さを持たないチャンネルには効かず、音源の範囲の外に出る音はオクターブ単位で内側へ 折り返す(crate::transposed_key)。整数の計算だけで、バイナリの形式は変わらない。

Source

pub fn transpose(&self) -> i8

再生中の移調(Sequencer::set_transpose)。

Source

pub fn set_range(&mut self, start: u64, end: Option<u64>)

再生範囲を決めて、start へ移動する(Sequencer::seek)。end が None なら曲の終わりまで。 end に着くと、曲の終わりと同じように止まる(set_looping ならループ点へ、なければ start へ戻る)。範囲の頭までの状態は seek と同じ方法で作る(頭から読み直し、音色・パラメータ・ テンポ・エンベロープ類の選択だけを送る。音は鳴らさない)。位置の表は足さないので、形式は 変わらない。範囲より前から続く音(長いタイ)は、範囲の頭では鳴らさない。

Source

pub fn range(&self) -> (u64, Option<u64>)

再生範囲(start, end)。範囲を決めていなければ(0, None)。

Source

pub fn jump_to_marker(&mut self, marker: u8, at: JumpAt) -> bool

マーカー(書いた順の番号、Header::markers 個)へ移動する。at で移動する時を選ぶ (JumpAt::Now は次の step で)。待っている間にもう一度呼ぶと新しい方で置き換える。 番号がなければ何もせず false。移動したら通知 SeqNotice::Jumped を出す。 終わった曲では at によらず次の step で移り、そこから鳴らす。

Source

pub fn cancel_jump(&mut self)

待っているマーカーへの移動を取り消す。

Source

pub fn marker_tick(&self, index: u8) -> Option<u64>

マーカー index の位置(tick)。

Source

pub fn set_notify(&mut self, mask: NoticeMask)

受け取る通知を選ぶ(既定は NoticeMask::DEFAULT:拍と小節以外)。

Source

pub fn poll_notice(&mut self) -> Option<SeqNotice>

たまった通知を古い順に 1 つ取り出す(NOTICE_CAPACITY 個まで。あふれたら古いものから捨てる)。

Source

pub fn stop(&mut self)

止める(以降は無音)。Sequencer::seek か Sequencer::restart で再び鳴らせる。

Source§

impl<'a, const TRACKS: usize> Sequencer<'a, TRACKS>

Source

pub fn new(data: &'a [u8], sample_rate: u32) -> Result<Self, DecodeError>

バイト列を検査して、再生の準備をする。

Source

pub fn unbind(self) -> Sequencer<'static, TRACKS>

曲データへの参照を外す。再生の進み具合(位置、テンポ、ループ回数、各トラックの状態)はそのまま持つ。

戻り値は 'static で、曲データを借りていないので、曲データを自分で持つ構造体の中に入れておける (自己参照にならない)。鳴らす前に必ず Sequencer::bind で曲データを付け直すこと。 外したままの render は何も鳴らさない(無音)。

Source

pub fn bind<'b>(self, data: &'b [u8]) -> Option<Sequencer<'b, TRACKS>>

曲データを付け直す(Sequencer::unbind の逆)。進み具合は変わらない。

data は Sequencer::new で検査したものと同じバイト列でなければならない。 長さまたは内容が違えば None を返す(再検査はしない。ヒープも使わない)。

Source

pub fn header(&self) -> &Header

Source

pub fn position(&self) -> u64

現在の位置(tick。4分音符あたり Header::ppq)。

Source

pub fn is_finished(&self) -> bool

Source

pub fn loops_done(&self) -> u32

Source

pub fn set_looping(&mut self, on: bool)

終わりまで来たらループ点(なければ頭)に戻るか。

Source

pub fn set_loop_limit(&mut self, n: Option<u32>)

ループで戻る回数の上限(None で無限)。

Source

pub fn set_audible(&mut self, mask: u32)

鳴らすチャンネルのビットマスク(ミュートとソロ用)。

Source

pub fn set_volume(&mut self, v: f32)

全体の音量(1.0 が等倍)。

Source

pub fn audible(&self) -> u32

鳴らすチャンネルのビットマスク(Sequencer::set_audible)。

Source

pub fn volume(&self) -> f32

全体の音量(Sequencer::set_volume)。

Trait Implementations§

Source§

impl<const N: usize> SfxSource for Sequencer<'_, N>

Source§

fn step(&mut self, synth: &mut dyn Synth) -> bool

一時停止している効果音は、進めずに鳴っている扱いにする(枠を返さない)。

Auto Trait Implementations§

§

impl<'a, const TRACKS: usize> Forget for Sequencer<'a, TRACKS>

§

impl<'a, const TRACKS: usize> Freeze for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: Freeze,

§

impl<'a, const TRACKS: usize> Move for Sequencer<'a, TRACKS>

§

impl<'a, const TRACKS: usize> RefUnwindSafe for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: RefUnwindSafe,

§

impl<'a, const TRACKS: usize> Send for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: Send,

§

impl<'a, const TRACKS: usize> Sync for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: Sync,

§

impl<'a, const TRACKS: usize> Unpin for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: Unpin,

§

impl<'a, const TRACKS: usize> UnsafeUnpin for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: UnsafeUnpin,

§

impl<'a, const TRACKS: usize> UnwindSafe for Sequencer<'a, TRACKS>
where [Cursor; TRACKS]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.