1- use sdl2 :: event :: Event ;
2- use sdl2 :: keyboard :: Keycode ;
1+ use projectm_rs :: core :: { projectm , projectm_handle } ;
2+ use projectm_rs :: playlist ;
33use sdl2:: video:: GLProfile ;
44
5- use projectm_rs :: core :: { projectm , projectm_handle } ;
5+ pub mod main_loop ;
66
7- use crate :: dummy_audio;
7+ pub struct Config {
8+ pub preset_path : Option < String > ,
9+ }
10+
11+ impl Default for Config {
12+ fn default ( ) -> Self {
13+ // default preset path
14+ Self {
15+ // load from home dir or w/e
16+ preset_path : Some ( String :: from ( "/usr/local/share/projectM/presets" ) ) ,
17+ }
18+ }
19+ }
820
921pub struct App {
1022 pm : projectm_handle ,
23+ playlist : playlist:: Playlist ,
1124 sdl_context : sdl2:: Sdl ,
1225 gl_context : sdl2:: video:: GLContext ,
1326 window : sdl2:: video:: Window ,
1427}
1528
1629impl App {
17- pub fn new ( ) -> Self {
30+ pub fn new ( config : Option < Config > ) -> Self {
1831 // setup sdl
1932 let sdl_context = sdl2:: init ( ) . unwrap ( ) ;
2033 let video_subsystem = sdl_context. video ( ) . unwrap ( ) ;
@@ -35,7 +48,7 @@ impl App {
3548 let window_width = display_mode. w as u32 ;
3649 let window_height = display_mode. h as u32 ;
3750 let window = video_subsystem
38- . window ( "frontend-sdl2-rust " , window_width, window_height)
51+ . window ( "ProjectM " , window_width, window_height)
3952 . opengl ( )
4053 . position_centered ( )
4154 . allow_highdpi ( )
@@ -48,48 +61,40 @@ impl App {
4861
4962 // initialize projectM
5063 let pm = projectm:: create ( ) ;
64+ // and a preset playlist
65+ let mut playlist = projectm_rs:: playlist:: Playlist :: create ( pm) ;
5166
5267 // get/set window size
5368 let ( width, height) = window. drawable_size ( ) ; // highDPI aware
5469 projectm:: set_window_size ( pm, width. try_into ( ) . unwrap ( ) , height. try_into ( ) . unwrap ( ) ) ;
5570
56- println ! ( "projectm initialized!" ) ;
57- Self {
71+ let mut this = Self {
5872 pm,
73+ playlist,
5974 sdl_context,
6075 gl_context,
6176 window,
62- }
63- }
64-
65- pub fn main_loop ( & mut self ) {
66- // events
67- let mut event_pump = self . sdl_context . event_pump ( ) . unwrap ( ) ;
68-
69- // renderLoop
70- ' running: loop {
71- // check for event
72- for event in event_pump. poll_iter ( ) {
73- match event {
74- Event :: Quit { .. }
75- | Event :: KeyDown {
76- keycode : Some ( Keycode :: Escape ) ,
77- ..
78- } => {
79- break ' running;
80- }
81- _ => { }
82- }
83- }
77+ } ;
8478
85- // generate random audio
86- dummy_audio:: generate_random_audio_data ( self . pm ) ;
79+ // read config
80+ if let Some ( config) = config {
81+ this. load_config ( config) ;
82+ }
8783
88- // render a frame
89- projectm :: render_frame ( self . pm ) ;
84+ this
85+ }
9086
91- // swap buffers
92- self . window . gl_swap_window ( ) ;
87+ pub fn load_config ( & mut self , config : Config ) {
88+ // load presets if provided
89+ if let Some ( preset_path) = config. preset_path {
90+ self . add_preset_path ( & preset_path) ;
9391 }
9492 }
93+
94+ /// Add presets to the playlist recursively skipping duplicates.
95+ pub fn add_preset_path ( & mut self , preset_path : & str ) {
96+ self . playlist . add_path ( preset_path, true ) ;
97+ println ! ( "added preset path: {}" , preset_path) ;
98+ println ! ( "playlist size: {}" , self . playlist. len( ) ) ;
99+ }
95100}
0 commit comments