[obsidian] vault backup: 2025-08-27 17:29:08[
This commit is contained in:
@@ -64,8 +64,8 @@ type Generator<T> = iVec<T>
|
||||
|
||||
```
|
||||
//Freq440Hz,Gain1.0,Phase0.0
|
||||
let Track1 = Generator::SineWave(Constant(440),Constant(1.0),Constant(0.0));
|
||||
let Track2 = Generator::SineWave(Track1,Constant(1.0),Constant(0.0));
|
||||
let t1 = Track(Generator::SineWave(Constant(440),Constant(1.0),Constant(0.0)));
|
||||
let t2 = Track(Generator::SineWave(t1,Constant(1.0),Constant(0.0)));
|
||||
```
|
||||
これをあんまり動的ディスパッチじゃない感じで実装したい。そしてこの辺までは別にMaxとかと同じレベルの話
|
||||
|
||||
@@ -76,19 +76,50 @@ CubaseにおけるインストゥルメントトラックとかはMIDIトラッ
|
||||
|
||||
## 考えうるユースケース
|
||||
|
||||
```rust
|
||||
type Region = {
|
||||
start:float,
|
||||
dur:float,
|
||||
content: ()->float,
|
||||
}
|
||||
```
|
||||
|
||||
### 一般的なリージョンエフェクト
|
||||
|
||||
```rust
|
||||
type alias FX = ({s:float,start:float,dur:float})->float
|
||||
fn region_transformer(origin:Region,fx:FX) -> 'Region{
|
||||
let start = origin.start
|
||||
let dur = origin.dur
|
||||
'Region{
|
||||
start:$start,
|
||||
dur:$dur,
|
||||
content: || {s:$origin.content(),start:$start,dur:$dur} |> $fx
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### リージョンに対するFadeInOut
|
||||
|
||||
```rust
|
||||
fn fade_inout(origin:Region)->Region{
|
||||
let time_in = Param(0.0,"fade_in",0..=f64::MAX);
|
||||
let time_out = Param(0.0,"fade_out",0..=f64::MAX);
|
||||
//クロージャとして値を閉じ込める
|
||||
let new_generator = |s| apply_fadeinout(s,time_in,time_out);
|
||||
Region{
|
||||
start:origin.start,
|
||||
dur:origin.dur,
|
||||
content: compose(origin.content,new_generator)//この辺がよくわからん
|
||||
}
|
||||
fn apply_fadeinout(s,start,tin,dur,tout){
|
||||
let end = start+dur
|
||||
if now < start | now > end | tin<=0 | tout <= 0{
|
||||
0
|
||||
}else{
|
||||
let gain_s = min(max(now - start,0)/tin ,1)
|
||||
let gain_e = min(max(end - now,0)/tout,1)
|
||||
s*gain_s*gain_e // gain_sとgain_eはどちらから0~1の区間もう片方が1
|
||||
}
|
||||
}
|
||||
fn fade_inout(origin:Region)-> 'Region{
|
||||
let new_generator = |s,start,dur| {
|
||||
//パラメーターはステージ1では単なる変数参照になる
|
||||
let time_in = Param!(0.0,"fade_in",0..=f64::MAX);
|
||||
let time_out = Param!(0.0,"fade_out",0..=f64::MAX);
|
||||
apply_fadeinout(s,start,time_in,dur, time_out)
|
||||
};
|
||||
region_transformer(origin,new_generator)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -97,13 +128,15 @@ fn fade_inout(origin:Region)->Region{
|
||||
```rust
|
||||
fn reverse(origin:Region)->Region{
|
||||
//クロージャとして値を閉じ込める
|
||||
let mut new_cache = vec![0;origin.get_dur_in_samples()*origin.channeks];
|
||||
origin.render(new_cache);
|
||||
let new_generator = |s| ;
|
||||
let new_cache = origin |> render
|
||||
|
||||
Region{
|
||||
start:origin.start,
|
||||
dur:origin.dur,
|
||||
content: compose(origin.content,new_generator)//この辺がよくわからん
|
||||
content: | | {
|
||||
let index = origin.dur - origin.start - now
|
||||
new_cache[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user