Skip to content

Commit

Permalink
Merge pull request #95 from muzik-apps/working
Browse files Browse the repository at this point in the history
v0.7.1-Audio Freedom Lab🥼(minor-update)
  • Loading branch information
waveyboym authored Dec 23, 2024
2 parents c03b61a + 0ec6c31 commit bc8abbe
Show file tree
Hide file tree
Showing 45 changed files with 438 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
releaseName: 'v__VERSION__-Audio Freedom Lab🥼'
releaseName: 'v__VERSION__-Audio Freedom Lab🥼(minor-update)'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
Expand Down
4 changes: 2 additions & 2 deletions muzik-offline/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion muzik-offline/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "muzik-offline",
"private": true,
"version": "0.7.0",
"version": "0.7.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion muzik-offline/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion muzik-offline/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "muzik-offline"
version = "0.7.0"
version = "0.7.1"
description = "A desktop music player for listening to music offline."
authors = ["Michael"]
license = "MIT"
Expand Down
25 changes: 15 additions & 10 deletions muzik-offline/src-tauri/src/app/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ use crate::utils::general_utils::get_random_port;
use super::setup_macos;

/// Initializes the kira audio manager with required settings.
pub fn initialise_kira_audio_manager() -> Arc<Mutex<KiraManager>> {
let audio_manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())
.expect("failed to initialize audio manager");
Arc::new(Mutex::new(KiraManager {
manager: audio_manager,
instance_handle: None,
volume: 0.0,
crossfade: false,
duration: None,
}))
pub fn initialise_kira_audio_manager() -> Arc<Mutex<Option<KiraManager>>> {
match AudioManager::<DefaultBackend>::new(AudioManagerSettings::default()){
Ok(audio_manager) => {
Arc::new(Mutex::new(Some(KiraManager {
manager: audio_manager,
instance_handle: None,
volume: 0.0,
crossfade: false,
duration: None,
})))
}
Err(_) => {
Arc::new(Mutex::new(None))
}
}
}

/// Initializes the Rodio audio manager with required settings.
Expand Down
3 changes: 2 additions & 1 deletion muzik-offline/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use database::db_api::{
use database::db_manager::DbManager;
use export::{export_csv::export_songs_as_csv, export_html::export_songs_as_html,
export_json::export_songs_as_json,export_txt::export_songs_as_txt, export_xml::export_songs_as_xml};
use music::player::set_playback_speed;
use music::player::{get_available_audio_backends, set_playback_speed};
//use export::export_pdf::export_songs_as_pdf;
use socials::discord_rpc::{set_discord_rpc_activity_with_timestamps, DiscordRpc};
use utils::music_list_organizer::MLO;
Expand Down Expand Up @@ -99,6 +99,7 @@ fn main() {
detect_deleted_songs,
collect_env_args,
// MUSIC PLAYER
get_available_audio_backends,
load_and_play_song_from_path,
load_a_song_from_path,
pause_song,
Expand Down
89 changes: 79 additions & 10 deletions muzik-offline/src-tauri/src/music/kira_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{sync::{Arc, Mutex}, time::Duration};
use tauri::State;

pub fn load_and_play_song_from_path_kira(
audio_manager: State<'_, Arc<Mutex<KiraManager>>>,
audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>,
sound_path: &str,
volume: f64,
duration: f64,
Expand All @@ -19,6 +19,13 @@ pub fn load_and_play_song_from_path_kira(
) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

//stop and clear all sounds that are playing
match &mut manager.instance_handle {
Some(handle) => {
Expand Down Expand Up @@ -113,7 +120,7 @@ pub fn load_and_play_song_from_path_kira(
}

pub fn load_a_song_from_path_kira(
audio_manager: State<'_, Arc<Mutex<KiraManager>>>,
audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>,
sound_path: &str,
volume: f64,
duration: f64,
Expand All @@ -122,6 +129,13 @@ pub fn load_a_song_from_path_kira(
) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

//stop and clear all sounds that are playing
match &mut manager.instance_handle {
Some(handle) => {
Expand Down Expand Up @@ -227,9 +241,16 @@ pub fn load_a_song_from_path_kira(
}
}

pub fn pause_song_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
pub fn pause_song_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.pause(Tween::default()) {
Expand All @@ -252,9 +273,16 @@ pub fn pause_song_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
}
}

pub fn stop_song_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
pub fn stop_song_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.stop(Tween::default()) {
Expand All @@ -277,9 +305,16 @@ pub fn stop_song_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
}
}

pub fn resume_playing_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
pub fn resume_playing_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.resume(Tween::default()) {
Expand All @@ -302,9 +337,15 @@ pub fn resume_playing_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) {
}
}

pub fn seek_to_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, position: f64) {
pub fn seek_to_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>, position: f64) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};
//get volume
let volume = manager.volume.clone();
match &mut manager.instance_handle {
Expand All @@ -329,9 +370,16 @@ pub fn seek_to_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, position:
}
}

pub fn seek_by_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, delta: f64) {
pub fn seek_by_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>, delta: f64) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.seek_by(delta) {
Expand All @@ -352,9 +400,16 @@ pub fn seek_by_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, delta: f6
}
}

pub fn get_song_position_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>) -> f64 {
pub fn get_song_position_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>) -> f64 {
let (pos, duration, cross_fade) = match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return 0.0;
}
};

match &mut manager.instance_handle {
Some(handle) => {
let song_position = handle.position();
Expand All @@ -378,9 +433,16 @@ pub fn get_song_position_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>)
return pos.as_secs_f64().floor();
}

pub fn set_volume_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, volume: f64) {
pub fn set_volume_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>, volume: f64) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.set_volume(volume, Tween::default()) {
Expand Down Expand Up @@ -461,9 +523,16 @@ fn handle_true_seeking(handle: &mut StreamingSoundHandle<FromFileError>, volume:
}
}

pub fn set_playback_speed_kira(audio_manager: State<'_, Arc<Mutex<KiraManager>>>, speed: f64) {
pub fn set_playback_speed_kira(audio_manager: State<'_, Arc<Mutex<Option<KiraManager>>>>, speed: f64) {
match audio_manager.lock() {
Ok(mut manager) => {
let manager = match manager.as_mut() {
Some(manager) => manager,
None => {
return;
}
};

match &mut manager.instance_handle {
Some(handle) => {
match handle.set_playback_rate(speed, Tween::default()) {
Expand Down
Loading

0 comments on commit bc8abbe

Please sign in to comment.