/* * Copyright (c) 2022 Contributors to the bevy-rrise project */ use bevy::log::LogPlugin; use bevy::prelude::*; use bevy_rrise::plugin::{CallbackChannel, RriseLabel, RrisePlugin}; use bevy_rrise::sound_engine::PostEventAtLocation; use bevy_rrise::AkCallbackEvent; use rrise::query_params::{get_rtpc_value, RtpcValueType}; use rrise::settings; use rrise::sound_engine::load_bank_by_name; use rrise::{AkAuxBusID, AkCallbackInfo, AkCallbackType, AkResult, AkRtpcValue}; use rrise_headers::rr; use std::path::PathBuf; #[cfg(windows)] use cc; fn main() { App::new() .add_plugins(DefaultPlugins.set(LogPlugin { filter: "bevy_rrise=debug,wgpu=error".to_string(), ..default() })) .add_plugin( RrisePlugin::default().with_engine_settings( settings::AkInitSettings { #[cfg(not(wwrelease))] install_assert_hook: true, ..default() } .with_plugin_dll_path(get_example_dll_path()), ), ) .insert_resource(Meters { meters: [ (rr::xbus::Meters_00, 0.), (rr::xbus::Meters_01, 0.), (rr::xbus::Meters_02, 0.), (rr::xbus::Meters_03, 0.), (rr::xbus::Meters_04, 0.), (rr::xbus::Meters_05, 0.), (rr::xbus::Meters_06, 0.), (rr::xbus::Meters_07, 0.), (rr::xbus::Meters_08, 0.), (rr::xbus::Meters_09, 0.), (rr::xbus::Meters_10, 0.), ], }) .add_startup_system(setup_scene) .add_startup_system(start_music.pipe(error_handler)) .add_system_to_stage( CoreStage::PreUpdate, audio_metering .pipe(error_handler) .after(RriseLabel::RriseCallbackEventsPopulated), ) .add_system(visualize_music) .add_system(update_beat_bar_times) .run(); } fn error_handler(In(result): In>) { if let Err(akr) = result { panic!("Unexpected error in system: {}", akr); } } #[derive(Component)] struct BandMeter(usize); #[derive(Component)] struct BeatBarText; type Meter = (AkAuxBusID, AkRtpcValue); #[derive(Resource)] struct Meters { meters: [Meter; 11], } fn audio_metering(mut meters: ResMut) -> Result<(), AkResult> { for meter in &mut meters.meters { let rtpc_value = get_rtpc_value(meter.0, None, None, RtpcValueType::Global(0.))?; meter.1 = match rtpc_value { RtpcValueType::Global(v) => v, _ => 0., }; } Ok(()) } fn visualize_music(mut visual_meters: Query<(&mut Transform, &BandMeter)>, meters: Res) { for (mut tfm, meter_index) in visual_meters.iter_mut() { let y_scale = 10. * (meters.meters[meter_index.0].1 + 48.) / 54.; tfm.scale = Vec3::new(1., y_scale, 1.); } } fn update_beat_bar_times( mut beat_bar_text: Query<&mut Text, With>, time: Res