Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

1.4 KB
Raw Blame
//! This example demonstrates how to bypass effects.

use bevy::prelude::*;
use bevy_seedling::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, SeedlingPlugins))
        .add_systems(Startup, route_input)
        .add_systems(Update, bypass)
        .run();
}

/// Here we route the input node, `AudioGraphInput`, to the `MainBus`.
fn route_input(
    input: Single<Entity, With<SamplerPool<DefaultPool>>>,
    server: Res<AssetServer>,
    mut commands: Commands,
) {
    commands
        .entity(*input)
        .disconnect(MainBus)
        // route the sound through a ton of reverb
        .chain_node(FreeverbNode {
            room_size: 0.9,
            damping: 0.8,
            width: 0.8,
            ..Default::default()
        })
        .connect(MainBus);

    commands.spawn(SamplePlayer::new(server.load("divine_comedy.ogg")));
}

fn bypass(
    interaction: Res<ButtonInput<KeyCode>>,
    freeverb: Single<(Entity, Has<AudioBypass>), With<FreeverbNode>>,
    mut commands: Commands,
) {
    if interaction.just_pressed(KeyCode::Space) {
        let (entity, bypassed) = freeverb.into_inner();

        if bypassed {
            info!("Removing bypass...");
            commands.entity(entity).remove::<AudioBypass>();
        } else {
            info!("Bypassing reverb...");
            commands.entity(entity).insert(AudioBypass);
        }
    }
}