Skip to content

Commit

Permalink
midi to ogg convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
dansgithubuser committed Sep 1, 2024
1 parent a8f5dfb commit 476c8f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion components/liner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ component!(
"sample_rate",
{"name": "connect_info", "args": "view", "flavor": "multi"},
{"name": "disconnect_info", "args": "view", "flavor": "multi"},
{"name": "field_helpers", "fields": ["repeat"], "kinds": ["rw"]},
],
{
queue: Queue,
lines: Vec<Box<Line>>,
samples: u32,
outputs: Vec<Option<View>>,
repeat: bool,
},
{
"get_midi": {
Expand Down Expand Up @@ -297,6 +299,7 @@ impl ComponentTrait for Component {
for _ in 0..16 {
self.lines.push(Box::new(Line::default()));
}
self.repeat = true;
}

fn connect(&mut self, body: serde_json::Value) -> CmdResult {
Expand Down Expand Up @@ -341,7 +344,7 @@ impl ComponentTrait for Component {
None,
);
}
if done {
if done && self.repeat {
self.samples = 0;
for line in &mut self.lines {
line.reset();
Expand Down
22 changes: 18 additions & 4 deletions systems/soundfont.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
import dlal

import argparse
from pathlib import Path

parser = argparse.ArgumentParser()
parser.add_argument('--midi-path', '-m')
parser.add_argument('--midi-path', '-m', type=Path)
parser.add_argument('--gain', '-g', type=float, default=1.0)
parser.add_argument('--ogg', action='store_true')
parser.add_argument('--extra', type=float, default=0.0)
args = parser.parse_args()

audio = dlal.Audio(driver=True)
comm = dlal.Comm()
liner = dlal.Liner()
soundfont = dlal.Soundfont()
gain = dlal.Gain(args.gain)
buf = dlal.Buf()
tape = dlal.Tape()

for i in range(16):
liner.connect(soundfont)
dlal.connect(
soundfont,
[buf, '<+', gain],
[audio, tape],
)

duration = None
if args.midi_path:
liner.load(args.midi_path, immediate=True)
duration = liner.duration()

dlal.typical_setup(duration=duration)
liner.repeat(False)
duration = liner.duration() + args.extra
flac_path = args.midi_path.with_suffix('.flac')
dlal.typical_setup(
duration=duration,
flac_path=flac_path,
)
if args.ogg:
sound = dlal.sound.read(flac_path)
sound.to_ogg(args.midi_path.with_suffix('.ogg'))

0 comments on commit 476c8f9

Please sign in to comment.