1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Enable missing_docs warning but allow it on specific modules that need work
//! Bevy audio plugin for YM2149 PSG emulator
//!
//! This crate provides a Bevy plugin for playing YM2149 audio files with real-time visualization
//! using the high-fidelity [ym2149](https://crates.io/crates/ym2149) emulator library.
//!
//! The plugin handles all aspects of YM file playback through Bevy's ECS architecture:
//! - File loading and metadata extraction
//! - Time-accurate frame advancement and audio generation
//! - Real-time visualization of channel activity
//! - Flexible playback control (play, pause, restart, volume)
//!
//! # Features
//!
//! - **Real-time YM2149 Audio Playback**: Stream YM2-YM6 format files with cycle-accurate emulation
//! - **Flexible Playback Control**: Play, pause, restart, volume adjustment, and loop support
//! - **Live Channel Visualization**: Real-time visual feedback for all three PSG channels with frequency/note info
//! - **Metadata Display**: Automatic extraction and display of song title and artist information
//! - **Frame-by-Frame Access**: Direct access to individual playback frames for analysis
//! - **Time-Accurate Pacing**: Proper time-based frame advancement matching original YM file rate
//! - **Audio Buffering**: Ring buffer architecture for smooth, artifact-free playback
//! - **Multiple Playbacks**: Support for simultaneous independent YM file playbacks
//!
//! # Quick Start
//!
//! ```no_run
//! use bevy::prelude::*;
//! use bevy_ym2149::{Ym2149Plugin, Ym2149Playback};
//!
//! fn main() {
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .add_plugins(Ym2149Plugin::default())
//! .add_systems(Startup, setup)
//! .run();
//! }
//!
//! fn setup(mut commands: Commands) {
//! commands.spawn(Camera2d::default());
//! commands.spawn(Ym2149Playback::new("path/to/song.ym"));
//! }
//! ```
//!
//! # Playback Control
//!
//! Control playback through the [`Ym2149Playback`] component:
//!
//! ```no_run
//! use bevy::prelude::*;
//! use bevy_ym2149::Ym2149Playback;
//!
//! fn playback_control(
//! mut playbacks: Query<&mut Ym2149Playback>,
//! keyboard: Res<ButtonInput<KeyCode>>,
//! ) {
//! for mut playback in playbacks.iter_mut() {
//! if keyboard.just_pressed(KeyCode::Space) {
//! if playback.is_playing() {
//! playback.pause();
//! } else {
//! playback.play();
//! }
//! }
//! if keyboard.just_pressed(KeyCode::ArrowUp) {
//! let new_volume = (playback.volume + 0.1).min(1.0);
//! playback.set_volume(new_volume);
//! }
//! }
//! }
//! ```
//!
//! # Visualization
//!
//! Visualization widgets now live in the companion crate `bevy_ym2149_viz`. Add
//! [`Ym2149VizPlugin`](https://docs.rs/bevy_ym2149_viz) alongside this crate's
//! [`Ym2149Plugin`] and use the helpers provided there to build UI components.
//!
//! # Architecture
//!
//! The plugin uses Bevy's ECS with three main systems:
//!
//! 1. **Initialization** - Loads YM files and creates emulator instances
//! 2. **Playback** - Advances frames using time-based pacing and generates audio
//! 3. **Visualization** - Updates UI with current playback state and channel information
//!
//! Audio flows through a thread-safe ring buffer from the emulator to rodio's audio device.
//!
//! # Module Organization
//!
//! - [`playback`] - Core playback component and state management
//! - [`plugin`] - Bevy plugin integration and systems
//! - [`audio_source`] - YM file loading and Bevy audio integration via Decodable
//! - [`bevy_ym2149_viz`](https://crates.io/crates/bevy_ym2149_viz) - Optional UI components and display helpers
// Public modules - user-facing API
// Semi-public modules - advanced features (documented but not primary API)
// Internal modules - implementation details (not part of public API)
pub
pub
pub
// Re-export ym2149 core types (kept for backwards compatibility; prefer importing from `ym2149`).
pub use *;
// Re-export common types from ym2149-common for unified API
pub use MetadataFields;
// === Primary Public API ===
// Plugin and configuration
pub use ;
// Playback control (main user-facing types)
pub use ;
// Register snapshot for visualization
pub use ChipStateSnapshot;
// Error handling
pub use ;
// Events for user systems to react to
pub use ;
// Music state machine
pub use ;
// Patterns for game integration
pub use ;
// Playlist support
pub use ;
// Synth controller
pub use YmSynthController;
// === Advanced API (documented, for power users) ===
// Audio bridge for custom audio routing
pub use ;
// Audio source for direct asset manipulation
pub use ;
// Oscilloscope buffer for visualization
pub use OscilloscopeBuffer;
// Advanced event types
pub use ;
// Advanced playlist control
pub use ;
// Music state processing
pub use process_music_state_requests;
// Diagnostics
pub use ;