-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data.txt
More file actions
10183 lines (9182 loc) · 328 KB
/
test_data.txt
File metadata and controls
10183 lines (9182 loc) · 328 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### USER
Use this rust example frontend for the projectM audio visualizer for a full audio player to the users requirments. The example starting, working, codebase is located at https://github.com/projectM-visualizer/frontend-sdl-rust
Use an appropriate GUI crate to create a full fledged music player that features that projectM visaulizer in the main central area of the window with important controls on 3 or 4 sides of this render area box and all other controls or settings inside of a settings window opened via a config > settings program top main menu bar along with file and help > about.
There should be able to be a playlist where the end user can add audio players to the playlist as a playback queue that can be rearranged and have new items added or current items removed.
there should also be some place where standard audio controls such as volume, a seek bar, and play/pause, next track, previous track, etc are located.
There should be a setting, saved persistently in a file within the programs user data directory in $HOME/.config (pick a name for this project that is unique and as short, memorable, and clever, as possible where the end user can have an "artist name" and a "social media link".
The artist name from this persistent and configurable setting should be added as one of the textual elements described below if there is no artist id3 tag info for the currently playing track. The song title if there is no title id3 tags should be the file name stripped of .mp3, .flag, .wav etc.
The social media link string should be configurable by the user.
These 3 strings should be drawing over the visualizer viewport area.
1 - The artist social media URL link should be drawn smaller and at 80% opacity, in pure white, at a certain font size, and using a certain font the user can select and defaulting to something either available in rust directly or common to most linux systems in /usr/share/fonts/ by default, but also configurable. It should default to being drawing in one of the 4 corners of the visualizer viewport at random taking into account inital anchor point and size of the font. This string drawing should then spend a certain period of configurable time in that corner and "transport" to another corner, endlessly.
2 - The artist name, whether gleamed from ID3 tags or overridden if set to a custom string, should start somewhere in the visualizer bounds, also starting at a default color, opacity, font, and font size, and when audio playback is started should have basic effects that can be enabled individually. The first effect is a simple translation of the drawn position that reflects off the viewports borders while taking into account font size dimensions with a small amount of randomness so that it doesn't get "stuck".
2.1 - After a certain period of configurable time the text will spend another configurable period of time getting more and more transparent to a configurable opacity level. It will then stay this way for the majority of the song. At the same time as when the fading effect started, and for the period of its duration, from the tracks end time, the very opposite effects of the fade out are done as a means of fading back in to be back at its initial state.
3 - The song title string has exactly the same features of "2 - The Artist Name" just done independantly (i.e. the two strings are not "attached" nor "linked" to eachother.
Keep in mind in the future there may be more advanced features like parsing song lyrics with a library like whisper to be displayed karaoke style, so the code should be kept as modular and well structured as possible with each file holding a specific purpose, and this will also prevent both your model and any other LLM models from getting confused. For the same reason try to use clear and obvious naming conventions when possible.
Ensure your code and all aspects of it is written to be easily read, rewritten, parsed, refactored, and any other modifications, best for your LLM model abilities.
This code will be git managed so create a .gitignore and a README.md as well as a docs/ directory with any important documentation, and especially regarding the config options that exist currently in the example projectM rust project as well as any that it is capable of, or any features we are adding.
Also keep in mind that after the initial logic and features are working flawlessly we will integrate (or you can integrate it as we go if deemed easy enough), the ability to record the visualizer viewport and its textual overlay layers into a video file to be shared on social media to promote the artist.
### ASSISTANT
<details type="reasoning" done="true" duration="144">
<summary>Thought for 144 seconds</summary>
> This is a complex request for creating a full-featured audio player with projectM visualization in Rust. Let me break down the requirements:
>
> 1. Use the existing projectM-visualizer/frontend-sdl-rust as a starting point
> 2. Create a GUI with projectM visualization in the center and controls on 3-4 sides
> 3. Include a menu bar with File, Config > Settings, and Help > About options
> 4. Implement a playlist system that allows adding, removing, and reordering tracks
> 5. Add standard audio controls (volume, seek bar, play/pause, next/previous)
> 6. Implement persistent settings in $HOME/.config with a unique project name
> 7. Allow configuration of artist name and social media link
> 8. Display text overlays on the visualizer:
> - Social media URL: moves between corners, configurable
> - Artist name: bouncing effect with fade in/out
> - Song title: same as artist name but independent
> 9. Keep code modular for future features (like lyrics display)
> 10. Create proper documentation, .gitignore, and README.md
> 11. Plan for future video recording feature
>
> For the GUI crate, I'll use `egui` which is a modern, easy-to-use immediate mode GUI for Rust that integrates well with SDL.
>
> Let me start by creating the project structure and then implement each component step by step.
>
> First, I need to come up with a unique, short, memorable, and clever project name. Let's go with "VibeStream" - it suggests both the visual aspect and the streaming/playing of audio.
>
> Now, let's create the project structure:
>
> ```
> vibestream/
> ├── .gitignore
> ├── Cargo.toml
> ├── README.md
> ├── docs/
> │ ├── configuration.md
> │ └── features.md
> └── src/
> ├── main.rs
> ├── app/
> │ ├── mod.rs
> │ ├── app.rs
> │ └── settings.rs
> ├── audio/
> │ ├── mod.rs
> │ ├── player.rs
> │ └── playlist.rs
> ├── ui/
> │ ├── mod.rs
> │ ├── main_window.rs
> │ ├── controls.rs
> │ ├── playlist_view.rs
> │ └── settings_window.rs
> ├── visualization/
> │ ├── mod.rs
> │ ├── projectm_wrapper.rs
> │ └── text_overlay.rs
> └── config/
> ├── mod.rs
> └── config.rs
> ```
>
> Now, let's implement each component:
>
> 1. Cargo.toml - Dependencies
> 2. .gitignore
> 3. README.md
> 4. Main application structure
> 5. Configuration system
> 6. Audio playback and playlist management
> 7. Visualization with text overlays
> 8. UI components
> 9. Documentation
>
> Let's start with the Cargo.toml:
>
> ```toml
> [package]
> name = "vibestream"
> version = "0.1.0"
> edition = "2021"
> authors = ["Your Name"]
> description = "Audio player with projectM visualization"
>
> [dependencies]
> sdl2 = "0.35"
> egui = "0.22"
> egui-sdl2 = "0.22"
> projectm = "0.1"
> rodio = "0.17"
> serde = { version = "1.0", features = ["derive"] }
> serde_json = "1.0"
> dirs = "5.0"
> rand = "0.8"
> anyhow = "1.0"
> log = "0.4"
> env_logger = "0.10"
> id3 = "1.7"
> ```
>
> Now, the .gitignore:
>
> ```
> # Rust
> target/
> Cargo.lock
>
> # IDE
> .vscode/
> .idea/
>
> # OS
> .DS_Store
> Thumbs.db
>
> # Config files (user-specific)
> *.local
>
> # Logs
> *.log
> ```
>
> README.md:
>
> ```markdown
> # VibeStream
>
> VibeStream is an audio player with projectM visualization, designed for artists to showcase their music with captivating visuals.
>
> ## Features
>
> - Audio playback with support for various formats
> - projectM visualization in the center of the window
> - Playlist management with drag-and-drop support
> - Text overlays for artist information and social media links
> - Configurable settings with persistent storage
> - Future support for video recording of visualizations
>
> ## Building
>
> Prerequisites:
> - Rust
> - SDL2 development libraries
> - projectM libraries
>
> ```bash
> git clone https://github.com/yourusername/vibestream.git
> cd vibestream
> cargo build --release
> ```
>
> ## Usage
>
> Run the application:
>
> ```bash
> cargo run
> ```
>
> ## Configuration
>
> Configuration is stored in `$HOME/.config/vibestream/config.json`.
>
> ## License
>
> [Your chosen license]
> ```
>
> Now, let's implement the main components:
>
> src/main.rs:
> ```rust
> use anyhow::Result;
> use sdl2::event::Event;
> use sdl2::keyboard::Keycode;
> use sdl2::video::Window;
> use std::time::Duration;
> use vibestream::app::VibeStreamApp;
> use vibestream::config::Config;
>
> fn main() -> Result<()> {
> // Initialize logger
> env_logger::init();
>
> // Load configuration
> let config = Config::load()?;
>
> // Initialize SDL
> let sdl_context = sdl2::init()?;
> let video_subsystem = sdl_context.video()?;
> let audio_subsystem = sdl_context.audio()?;
>
> // Create window
> let window = video_subsystem
> .window("VibeStream", 1200, 800)
> .position_centered()
> .resizable()
> .opengl()
> .build()?;
>
> // Initialize egui
> let (egui_ctx, egui_state) = egui_sdl2::with_sdl2(&window, &video_subsystem);
>
> // Initialize the app
> let mut app = VibeStreamApp::new(config, window, audio_subsystem)?;
>
> // Main loop
> let mut event_pump = sdl_context.event_pump()?;
> let mut running = true;
>
> while running {
> // Handle input
> for event in event_pump.poll_iter() {
> match event {
> Event::Quit { .. } => running = false,
> Event::KeyDown {
> keycode: Some(Keycode::Escape),
> ..
> } => running = false,
> _ => {
> // Forward events to egui
> egui_state.process_input(&window, &event, &mut app.painter);
> }
> }
> }
>
> // Update the app
> app.update(Duration::from_secs_f32(1.0 / 60.0))?;
>
> // Render
> app.render(&egui_ctx)?;
> }
>
> // Save configuration before exit
> app.save_config()?;
>
> Ok(())
> }
> ```
>
> src/app/mod.rs:
> ```rust
> pub mod app;
> pub mod settings;
>
> pub use app::VibeStreamApp;
> pub use settings::Settings;
> ```
>
> src/app/settings.rs:
> ```rust
> use serde::{Deserialize, Serialize};
> use std::path::PathBuf;
>
> #[derive(Debug, Clone, Serialize, Deserialize)]
> pub struct Settings {
> pub artist_name: Option<String>,
> pub social_media_link: Option<String>,
> pub font_path: PathBuf,
> pub font_size: u16,
> pub text_opacity: f32,
> pub text_color: [u8; 4],
> pub text_move_speed: f32,
> pub fade_duration_secs: f32,
> pub social_media_display_duration_secs: f32,
> pub social_media_font_size: u16,
> pub social_media_opacity: f32,
> }
>
> impl Default for Settings {
> fn default() -> Self {
> Self {
> artist_name: None,
> social_media_link: None,
> font_path: PathBuf::from("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"),
> font_size: 24,
> text_opacity: 1.0,
> text_color: [255, 255, 255, 255],
> text_move_speed: 100.0,
> fade_duration_secs: 5.0,
> social_media_display_duration_secs: 10.0,
> social_media_font_size: 16,
> social_media_opacity: 0.8,
> }
> }
> }
> ```
>
> src/app/app.rs:
> ```rust
> use anyhow::Result;
> use sdl2::audio::AudioSubsystem;
> use sdl2::video::Window;
> use std::time::Duration;
> use vibestream::audio::{AudioPlayer, Playlist};
> use vibestream::config::Config;
> use vibestream::ui::{MainWindow, SettingsWindow};
> use vibestream::visualization::{ProjectMWrapper, TextOverlay};
>
> pub struct VibeStreamApp {
> config: Config,
> window: Window,
> audio_subsystem: AudioSubsystem,
> audio_player: AudioPlayer,
> playlist: Playlist,
> visualization: ProjectMWrapper,
> text_overlay: TextOverlay,
> main_window: MainWindow,
> settings_window: SettingsWindow,
> show_settings: bool,
> painter: egui_sdl2::Painter,
> }
>
> impl VibeStreamApp {
> pub fn new(config: Config, window: Window, audio_subsystem: AudioSubsystem) -> Result<Self> {
> let painter = egui_sdl2::Painter::new(&window);
>
> // Initialize audio player
> let audio_player = AudioPlayer::new(&audio_subsystem)?;
>
> // Initialize playlist
> let playlist = Playlist::new();
>
> // Initialize visualization
> let visualization = ProjectMWrapper::new()?;
>
> // Initialize text overlay
> let text_overlay = TextOverlay::new(config.settings.clone());
>
> // Initialize UI components
> let main_window = MainWindow::new();
> let settings_window = SettingsWindow::new(config.settings.clone());
>
> Ok(Self {
> config,
> window,
> audio_subsystem,
> audio_player,
> playlist,
> visualization,
> text_overlay,
> main_window,
> settings_window,
> show_settings: false,
> painter,
> })
> }
>
> pub fn update(&mut self, delta_time: Duration) -> Result<()> {
> // Update audio player
> self.audio_player.update()?;
>
> // Update visualization
> self.visualization.update(&self.audio_player)?;
>
> // Update text overlay
> self.text_overlay.update(
> delta_time,
> &self.audio_player,
> &self.config.settings,
> )?;
>
> Ok(())
> }
>
> pub fn render(&mut self, egui_ctx: &egui::Context) -> Result<()> {
> // Clear the screen
> unsafe {
> gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
> }
>
> // Render visualization
> self.visualization.render()?;
>
> // Render text overlay
> self.text_overlay.render()?;
>
> // Render UI
> self.painter.paint_and_update_textures(
> egui_ctx,
> self.window.drawable_size(),
> |ctx| {
> if self.show_settings {
> self.settings_window.show(ctx, &mut self.config.settings);
> } else {
> self.main_window.show(
> ctx,
> &mut self.audio_player,
> &mut self.playlist,
> &mut self.show_settings,
> );
> }
> },
> );
>
> // Swap buffers
> self.window.gl_swap_window();
>
> Ok(())
> }
>
> pub fn save_config(&self) -> Result<()> {
> self.config.save()?;
> Ok(())
> }
> }
> ```
>
> src/config/mod.rs:
> ```rust
> pub mod config;
>
> pub use config::Config;
> ```
>
> src/config/config.rs:
> ```rust
> use anyhow::{Context, Result};
> use dirs::config_dir;
> use serde::{Deserialize, Serialize};
> use std::fs;
> use std::path::{Path, PathBuf};
> use vibestream::app::Settings;
>
> #[derive(Debug, Clone, Serialize, Deserialize)]
> pub struct Config {
> pub settings: Settings,
> pub config_path: PathBuf,
> }
>
> impl Config {
> pub fn load() -> Result<Self> {
> let config_dir = config_dir()
> .context("Failed to get config directory")?
> .join("vibestream");
>
> fs::create_dir_all(&config_dir)
> .context("Failed to create config directory")?;
>
> let config_path = config_dir.join("config.json");
>
> if config_path.exists() {
> let config_str = fs::read_to_string(&config_path)
> .context("Failed to read config file")?;
>
> let settings: Settings = serde_json::from_str(&config_str)
> .context("Failed to parse config file")?;
>
> Ok(Self {
> settings,
> config_path,
> })
> } else {
> let settings = Settings::default();
> let config = Self {
> settings: settings.clone(),
> config_path: config_path.clone(),
> };
>
> config.save()?;
>
> Ok(config)
> }
> }
>
> pub fn save(&self) -> Result<()> {
> let config_str = serde_json::to_string_pretty(&self.settings)
> .context("Failed to serialize config")?;
>
> fs::write(&self.config_path, config_str)
> .context("Failed to write config file")?;
>
> Ok(())
> }
> }
> ```
>
> src/audio/mod.rs:
> ```rust
> pub mod player;
> pub mod playlist;
>
> pub use player::AudioPlayer;
> pub use playlist::Playlist;
> ```
>
> src/audio/player.rs:
> ```rust
> use anyhow::Result;
> use rodio::{Decoder, OutputStream, Sink};
> use std::fs::File;
> use std::io::BufReader;
> use std::path::Path;
> use std::time::Duration;
>
> pub struct AudioPlayer {
> stream: OutputStream,
> sink: Option<Sink>,
> current_file: Option<String>,
> duration: Option<Duration>,
> position: Duration,
> volume: f32,
> paused: bool,
> }
>
> impl AudioPlayer {
> pub fn new(_audio_subsystem: &sdl2::audio::AudioSubsystem) -> Result<Self> {
> let (stream, _) = OutputStream::try_default()?;
>
> Ok(Self {
> stream,
> sink: None,
> current_file: None,
> duration: None,
> position: Duration::from_secs(0),
> volume: 1.0,
> paused: false,
> })
> }
>
> pub fn load_file(&mut self, path: &Path) -> Result<()> {
> let file = File::open(path)?;
> let reader = BufReader::new(file);
> let source = Decoder::new(reader)?;
>
> // Get duration if available
> let duration = source.total_duration();
>
> // Create new sink
> let sink = Sink::try_new(&self.stream.handle())?;
> sink.set_volume(self.volume);
> sink.append(source);
>
> self.sink = Some(sink);
> self.current_file = Some(path.to_string_lossy().to_string());
> self.duration = duration;
> self.position = Duration::from_secs(0);
> self.paused = false;
>
> Ok(())
> }
>
> pub fn play(&mut self) {
> if let Some(sink) = &self.sink {
> sink.play();
> self.paused = false;
> }
> }
>
> pub fn pause(&mut self) {
> if let Some(sink) = &self.sink {
> sink.pause();
> self.paused = true;
> }
> }
>
> pub fn toggle_play_pause(&mut self) {
> if self.paused {
> self.play();
> } else {
> self.pause();
> }
> }
>
> pub fn stop(&mut self) {
> if let Some(sink) = &self.sink {
> sink.stop();
> }
> self.sink = None;
> self.current_file = None;
> self.duration = None;
> self.position = Duration::from_secs(0);
> }
>
> pub fn set_volume(&mut self, volume: f32) {
> self.volume = volume.clamp(0.0, 1.0);
> if let Some(sink) = &self.sink {
> sink.set_volume(self.volume);
> }
> }
>
> pub fn get_volume(&self) -> f32 {
> self.volume
> }
>
> pub fn seek(&mut self, position: Duration) -> Result<()> {
> if let Some(current_file) = &self.current_file {
> let path = Path::new(current_file);
> self.load_file(path)?;
>
> if let Some(sink) = &self.sink {
> // This is a bit of a hack since rodio doesn't support seeking directly
> // We're just playing silence until we reach the desired position
> let silence = rodio::source::Zero::<f32>::new(1, 1);
> let silence_duration = rodio::Source::duration(&silence);
>
> if position < silence_duration {
> sink.append(silence.take_duration(position));
> }
> }
>
> self.position = position;
> }
>
> Ok(())
> }
>
> pub fn get_position(&self) -> Duration {
> if let Some(sink) = &self.sink {
> self.position + sink.get_pos()
> } else {
> self.position
> }
> }
>
> pub fn get_duration(&self) -> Option<Duration> {
> self.duration
> }
>
> pub fn is_playing(&self) -> bool {
> if let Some(sink) = &self.sink {
> !sink.is_paused() && !sink.empty()
> } else {
> false
> }
> }
>
> pub fn is_paused(&self) -> bool {
> self.paused
> }
>
> pub fn get_current_file(&self) -> Option<&str> {
> self.current_file.as_deref()
> }
>
> pub fn update(&mut self) -> Result<()> {
> // Update position if playing
> if self.is_playing() {
> self.position = self.get_position();
> }
>
> Ok(())
> }
> }
> ```
>
> src/audio/playlist.rs:
> ```rust
> use anyhow::Result;
> use std::path::PathBuf;
>
> #[derive(Debug, Clone)]
> pub struct PlaylistItem {
> pub path: PathBuf,
> pub title: Option<String>,
> pub artist: Option<String>,
> }
>
> impl PlaylistItem {
> pub fn new(path: PathBuf) -> Self {
> let mut title = None;
> let mut artist = None;
>
> // Try to read ID3 tags
> if let Ok(tag) = id3::Tag::read_from_path(&path) {
> title = tag.title().map(|s| s.to_string());
> artist = tag.artist().map(|s| s.to_string());
> }
>
> // If no title, use filename without extension
> if title.is_none() {
> if let Some(file_stem) = path.file_stem() {
> title = file_stem.to_string_lossy().to_string().into();
> }
> }
>
> Self {
> path,
> title,
> artist,
> }
> }
> }
>
> pub struct Playlist {
> items: Vec<PlaylistItem>,
> current_index: Option<usize>,
> }
>
> impl Playlist {
> pub fn new() -> Self {
> Self {
> items: Vec::new(),
> current_index: None,
> }
> }
>
> pub fn add_item(&mut self, path: PathBuf) {
> let item = PlaylistItem::new(path);
> self.items.push(item);
> }
>
> pub fn remove_item(&mut self, index: usize) {
> if index < self.items.len() {
> self.items.remove(index);
>
> // Adjust current index if needed
> if let Some(current) = self.current_index {
> if current == index {
> self.current_index = None;
> } else if current > index {
> self.current_index = Some(current - 1);
> }
> }
> }
> }
>
> pub fn move_item(&mut self, from_index: usize, to_index: usize) {
> if from_index < self.items.len() && to_index < self.items.len() && from_index != to_index {
> let item = self.items.remove(from_index);
> self.items.insert(to_index, item);
>
> // Adjust current index if needed
> if let Some(current) = self.current_index {
> if current == from_index {
> self.current_index = Some(to_index);
> } else if from_index < current && to_index >= current {
> self.current_index = Some(current - 1);
> } else if from_index > current && to_index <= current {
> self.current_index = Some(current + 1);
> }
> }
> }
> }
>
> pub fn get_items(&self) -> &Vec<PlaylistItem> {
> &self.items
> }
>
> pub fn get_current_item(&self) -> Option<&PlaylistItem> {
> self.current_index.and_then(|i| self.items.get(i))
> }
>
> pub fn get_current_index(&self) -> Option<usize> {
> self.current_index
> }
>
> pub fn set_current_index(&mut self, index: Option<usize>) {
> if let Some(i) = index {
> if i < self.items.len() {
> self.current_index = Some(i);
> } else {
> self.current_index = None;
> }
> } else {
> self.current_index = None;
> }
> }
>
> pub fn next(&mut self) -> Option<&PlaylistItem> {
> if self.items.is_empty() {
> return None;
> }
>
> let next_index = match self.current_index {
> Some(i) => (i + 1) % self.items.len(),
> None => 0,
> };
>
> self.current_index = Some(next_index);
> self.items.get(next_index)
> }
>
> pub fn previous(&mut self) -> Option<&PlaylistItem> {
> if self.items.is_empty() {
> return None;
> }
>
> let prev_index = match self.current_index {
> Some(0) => self.items.len() - 1,
> Some(i) => i - 1,
> None => self.items.len() - 1,
> };
>
> self.current_index = Some(prev_index);
> self.items.get(prev_index)
> }
>
> pub fn clear(&mut self) {
> self.items.clear();
> self.current_index = None;
> }
> }
> ```
>
> src/visualization/mod.rs:
> ```rust
> pub mod projectm_wrapper;
> pub mod text_overlay;
>
> pub use projectm_wrapper::ProjectMWrapper;
> pub use text_overlay::TextOverlay;
> ```
>
> src/visualization/projectm_wrapper.rs:
> ```rust
> use anyhow::Result;
> use std::ffi::CString;
> use vibestream::audio::AudioPlayer;
>
> pub struct ProjectMWrapper {
> projectm: projectm::ProjectM,
> width: u32,
> height: u32,
> }
>
> impl ProjectMWrapper {
> pub fn new() -> Result<Self> {
> let projectm = projectm::ProjectM::create(
> projectm::RenderTarget::Default,
> projectm::TextureSize::Small,
> projectm::DoubleBuffering::Enabled,
> )?;
>
> Ok(Self {
> projectm,
> width: 800,
> height: 600,
> })
> }
>
> pub fn update(&mut self, audio_player: &AudioPlayer) -> Result<()> {
> // Get audio data if available
> if let Some(_pcm) = audio_player.get_pcm_data() {
> // In a real implementation, we would pass PCM data to projectM
> // For now, we'll just generate a dummy texture
> }
>
> Ok(())
> }
>
> pub fn render(&mut self) -> Result<()> {
> // Render projectM visualization
> self.projectm.render_frame(
> self.width,
> self.height,
> 0, // time
> None, // texture
> )?;
>
> Ok(())
> }
>
> pub fn resize(&mut self, width: u32, height: u32) {
> self.width = width;
> self.height = height;
> }
> }
> ```
>
> src/visualization/text_overlay.rs:
> ```rust
> use anyhow::Result;
> use rand::Rng;
> use std::time::Duration;
> use vibestream::app::Settings;
> use vibestream::audio::AudioPlayer;
>
> #[derive(Debug, Clone)]
> pub enum Corner {
> TopLeft,
> TopRight,
> BottomLeft,
> BottomRight,
> }
>
> #[derive(Debug, Clone)]
> pub struct TextPosition {
> pub x: f32,
> pub y: f32,
> pub vx: f32,
> pub vy: f32,
> pub opacity: f32,
> pub fade_direction: i32, // -1 for fading out, 1 for fading in, 0 for stable
> }
>
> pub struct TextOverlay {
> artist_position: TextPosition,
> title_position: TextPosition,
> social_media_position: TextPosition,
> social_media_corner: Corner,
> social_media_timer: Duration,
> font: rusttype::Font<'static>,
> }
>
> impl TextOverlay {
> pub fn new(settings: Settings) -> Result<Self> {
> // Load font
> let font_data = std::fs::read(&settings.font_path)?;
> let font = rusttype::Font::try_from_vec(font_data)
> .ok_or_else(|| anyhow::anyhow!("Failed to load font"))?;
>
> // Initialize positions
> let artist_position = TextPosition {
> x: 100.0,
> y: 100.0,
> vx: 50.0,
> vy: 30.0,
> opacity: settings.text_opacity,
> fade_direction: 0,
> };
>
> let title_position = TextPosition {
> x: 100.0,
> y: 150.0,
> vx: -40.0,
> vy: 35.0,
> opacity: settings.text_opacity,
> fade_direction: 0,
> };
>
> let social_media_position = TextPosition {
> x: 10.0,
> y: 10.0,
> vx: 0.0,
> vy: 0.0,
> opacity: settings.social_media_opacity,
> fade_direction: 0,
> };
>
> let mut rng = rand::thread_rng();
> let social_media_corner = match rng.gen_range(0..4) {
> 0 => Corner::TopLeft,
> 1 => Corner::TopRight,
> 2 => Corner::BottomLeft,
> _ => Corner::BottomRight,
> };
>
> Ok(Self {
> artist_position,
> title_position,
> social_media_position,
> social_media_corner,
> social_media_timer: Duration::from_secs(0),
> font,
> })
> }
>
> pub fn update(&mut self, delta_time: Duration, audio_player: &AudioPlayer, settings: &Settings) -> Result<()> {
> let delta_secs = delta_time.as_secs_f32();
>
> // Update social media timer
> self.social_media_timer += delta_time;
>
> // Move social media link to a new corner if it's time
> if self.social_media_timer.as_secs_f32() >= settings.social_media_display_duration_secs {
> self.social_media_timer = Duration::from_secs(0);
>
> let mut rng = rand::thread_rng();
> self.social_media_corner = match rng.gen_range(0..4) {
> 0 => Corner::TopLeft,
> 1 => Corner::TopRight,
> 2 => Corner::BottomLeft,
> _ => Corner::BottomRight,
> };
> }
>
> // Update social media position based on corner
> match self.social_media_corner {
> Corner::TopLeft => {
> self.social_media_position.x = 10.0;
> self.social_media_position.y = 10.0;
> }
> Corner::TopRight => {
> self.social_media_position.x = 790.0; // Assuming 800px width
> self.social_media_position.y = 10.0;
> }
> Corner::BottomLeft => {
> self.social_media_position.x = 10.0;
> self.social_media_position.y = 590.0; // Assuming 600px height
> }
> Corner::BottomRight => {
> self.social_media_position.x = 790.0;