#![cfg_attr(
not(bela_device),
allow(
dead_code,
reason = "only the fallback main is reachable off-device; the application code should still compile and lint"
)
)]
#[cfg(bela_device)]
use std::env;
#[cfg(bela_device)]
use std::ffi::OsString;
use std::process::ExitCode;
use bela::{BelaApplication, RenderContext, SetupContext, ThreadInfo, rt_println};
const PERIOD_SIZE: u32 = 32;
struct Report;
impl BelaApplication for Report {
type RenderState = ();
fn setup(&mut self, context: &SetupContext) -> bool {
rt_println!(
"setup: {} Hz, {} frames per block, {} in / {} out audio channels, \
{} analog in / {} analog out, {} digital, {} render thread(s)",
context.audio_sample_rate(),
context.audio_frames(),
context.audio_in_channels(),
context.audio_out_channels(),
context.analog_in_channels(),
context.analog_out_channels(),
context.digital_channels(),
context.thread_count()
);
true
}
fn create_render_state(&mut self, _thread: ThreadInfo, _context: &SetupContext) {}
fn render(&self, _state: &mut (), _context: &mut RenderContext) {}
}
#[cfg(bela_device)]
fn usage() {
eprintln!("Usage: command_line [options]");
bela::print_usage();
eprintln!(" --help [-h]: Print this menu");
}
#[cfg(bela_device)]
fn main() -> ExitCode {
let args: Vec<OsString> = env::args_os().collect();
if args
.iter()
.skip(1)
.any(|arg| matches!(arg.to_str(), Some("-h" | "--help")))
{
usage();
return ExitCode::SUCCESS;
}
let settings = bela::Settings::new().period_size(PERIOD_SIZE);
match bela::Bela::run_with_args(Report, &settings, args) {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("Error: {error}");
if matches!(
error,
bela::Error::CommandLine(_) | bela::Error::CommandLineNul
) {
usage();
}
ExitCode::FAILURE
}
}
}
#[cfg(not(bela_device))]
fn main() -> ExitCode {
eprintln!("This example must be cross-compiled for Bela Gem (aarch64-unknown-linux-gnu).");
ExitCode::FAILURE
}