Start building a music player server (#17)
The very beginnings, with a very basic application architecture, for a music playing server on a headless system. This also adds my new Flow library, which I'll be wanting to use in a variety of places. Co-authored-by: Savanni D'Gerinel <savanni@luminescent-dreams.com> Reviewed-on: savanni/tools#17
This commit is contained in:
parent
cca1b9c3ba
commit
e60a2fbc30
|
@ -1,2 +1,4 @@
|
|||
target
|
||||
.direnv/
|
||||
node_modules
|
||||
dist
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
name = "changeset"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
hash::Hash,
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
name = "coordinates"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use coordinates::hex_map;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2022-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// Ĉi-tiu modulo enhavas la elementojn por kub-koordinato.
|
||||
///
|
||||
/// This code is based on https://www.redblobgames.com/grids/hexagons/
|
||||
|
|
|
@ -3,7 +3,8 @@ name = "emseries"
|
|||
version = "0.5.1"
|
||||
authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
||||
description = "an Embedded Time Series database"
|
||||
license = "BSD-3-Clause"
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
documentation = "https://docs.rs/emseries"
|
||||
homepage = "https://github.com/luminescent-dreams/emseries"
|
||||
repository = "https://github.com/luminescent-dreams/emseries"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use date_time_tz::DateTimeTz;
|
||||
use types::Recordable;
|
||||
|
||||
|
@ -8,14 +20,12 @@ pub trait Criteria {
|
|||
fn apply<T: Recordable>(&self, record: &T) -> bool;
|
||||
}
|
||||
|
||||
|
||||
/// Specify two criteria that must both be matched.
|
||||
pub struct And<A: Criteria, B: Criteria> {
|
||||
pub lside: A,
|
||||
pub rside: B,
|
||||
}
|
||||
|
||||
|
||||
impl<A, B> Criteria for And<A, B>
|
||||
where
|
||||
A: Criteria,
|
||||
|
@ -26,14 +36,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Specify two criteria, either of which may be matched.
|
||||
pub struct Or<A: Criteria, B: Criteria> {
|
||||
pub lside: A,
|
||||
pub rside: B,
|
||||
}
|
||||
|
||||
|
||||
/// Specify the starting time for a search. This consists of a UTC timestamp and a specifier as to
|
||||
/// whether the exact time is included in the search criteria.
|
||||
pub struct StartTime {
|
||||
|
@ -41,7 +49,6 @@ pub struct StartTime {
|
|||
pub incl: bool,
|
||||
}
|
||||
|
||||
|
||||
impl Criteria for StartTime {
|
||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||
if self.incl {
|
||||
|
@ -52,7 +59,6 @@ impl Criteria for StartTime {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Specify the ending time for a search. This consists of a UTC timestamp and a specifier as to
|
||||
/// whether the exact time is included in the search criteria.
|
||||
pub struct EndTime {
|
||||
|
@ -60,7 +66,6 @@ pub struct EndTime {
|
|||
pub incl: bool,
|
||||
}
|
||||
|
||||
|
||||
impl Criteria for EndTime {
|
||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||
if self.incl {
|
||||
|
@ -71,7 +76,6 @@ impl Criteria for EndTime {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Specify a list of tags that must exist on the record.
|
||||
pub struct Tags {
|
||||
pub tags: Vec<String>,
|
||||
|
@ -80,13 +84,10 @@ pub struct Tags {
|
|||
impl Criteria for Tags {
|
||||
fn apply<T: Recordable>(&self, record: &T) -> bool {
|
||||
let record_tags = record.tags();
|
||||
self.tags
|
||||
.iter()
|
||||
.all(|v| record_tags.contains(v))
|
||||
self.tags.iter().all(|v| record_tags.contains(v))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Specify a criteria that searches for records matching an exact time.
|
||||
pub fn exact_time(time: DateTimeTz) -> And<StartTime, EndTime> {
|
||||
And {
|
||||
|
@ -98,7 +99,6 @@ pub fn exact_time(time: DateTimeTz) -> And<StartTime, EndTime> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Specify a criteria that searches for all records within a time range.
|
||||
pub fn time_range(
|
||||
start: DateTimeTz,
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate chrono;
|
||||
extern crate chrono_tz;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// NOTE: this module is a candidate for extraction into its own crate, or should be replaced with
|
||||
// an existing crate.
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! An Embedded Time Series Database
|
||||
|
||||
This library provides a low-intensity time series database meant to be embedded inside of an
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate uuid;
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use date_time_tz::DateTimeTz;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::ser::Serialize;
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
|
|
28
flake.lock
28
flake.lock
|
@ -17,16 +17,16 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1672580127,
|
||||
"narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=",
|
||||
"lastModified": 1675918889,
|
||||
"narHash": "sha256-hy7re4F9AEQqwZxubct7jBRos6md26bmxnCjxf5utJA=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0874168639713f547c05947c76124f78441ea46c",
|
||||
"rev": "49efda9011e8cdcd6c1aad30384cb1dc230c82fe",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.05",
|
||||
"ref": "nixos-22.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
|
@ -52,7 +52,7 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"narHash": "sha256-GWnDfrKbQPb+skMMesm1WVu7a3y3GTDpYpfOv3yF4gc=",
|
||||
"narHash": "sha256-0eO3S+2gLODqDoloufeC99PfQ5mthuN9JADzqFXid1Y=",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
|
||||
},
|
||||
|
@ -64,7 +64,23 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"oxalica": "oxalica"
|
||||
"oxalica": "oxalica",
|
||||
"unstable": "unstable"
|
||||
}
|
||||
},
|
||||
"unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1675942811,
|
||||
"narHash": "sha256-/v4Z9mJmADTpXrdIlAjFa1e+gkpIIROR670UVDQFwIw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "724bfc0892363087709bd3a5a1666296759154b1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
18
flake.nix
18
flake.nix
|
@ -2,11 +2,12 @@
|
|||
description = "Lumenescent Dreams Tools";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
||||
nixpkgs.url = "nixpkgs/nixos-22.11";
|
||||
unstable.url = "nixpkgs/nixos-unstable";
|
||||
oxalica.url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, oxalica }:
|
||||
outputs = { self, nixpkgs, unstable, oxalica }:
|
||||
let
|
||||
version = builtins.string 0 8 self.lastModifiedDate;
|
||||
supportedSystems = [ "x86_64-linux" ];
|
||||
|
@ -16,6 +17,7 @@
|
|||
let
|
||||
rust_overlay = import oxalica;
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
|
||||
pkgs-unstable = import unstable { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
|
||||
rust = pkgs.rust-bin.stable."1.65.0".default.override {
|
||||
extensions = [ "rust-src" ];
|
||||
};
|
||||
|
@ -23,12 +25,24 @@
|
|||
pkgs.mkShell {
|
||||
name = "ld-tools-devshell";
|
||||
buildInputs = [
|
||||
pkgs.clang
|
||||
pkgs.entr
|
||||
pkgs.glade
|
||||
pkgs.glib
|
||||
pkgs.gst_all_1.gst-plugins-bad
|
||||
pkgs.gst_all_1.gst-plugins-base
|
||||
pkgs.gst_all_1.gst-plugins-good
|
||||
pkgs.gst_all_1.gst-plugins-ugly
|
||||
pkgs.gst_all_1.gstreamer
|
||||
pkgs.gtk4
|
||||
pkgs.nodejs
|
||||
pkgs.openssl
|
||||
pkgs.pipewire
|
||||
pkgs.pkg-config
|
||||
pkgs.sqlite
|
||||
rust
|
||||
];
|
||||
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "flow"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "flow"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
thiserror = "1"
|
|
@ -0,0 +1,3 @@
|
|||
# Flow
|
||||
|
||||
This is a library to help with application control flow, separating fatal errors from normal recoverable errors. This is almost entirely inspired by [Error Handling in a Correctness-Critical Rust Project](https://sled.rs/errors.html) in the sled.rs library.
|
|
@ -0,0 +1,257 @@
|
|||
//! Control Flow for Correctness-Critical applications
|
||||
//!
|
||||
//! https://sled.rs/errors.html
|
||||
//!
|
||||
//! Where the sled.rs library uses `Result<Result<A, Error>, FatalError>`, these are a little hard to
|
||||
//! work with. This library works out a set of utility functions that allow us to work with the
|
||||
//! nested errors in the same way as a regular Result.
|
||||
use std::error::Error;
|
||||
|
||||
/// Implement this trait for the application's fatal errors.
|
||||
///
|
||||
/// Fatal errors should be things that should trigger an application shutdown. Applications should
|
||||
/// not try to recover from fatal errors, but simply bring the app to the safest shutdown point and
|
||||
/// report the best possible information to the user.
|
||||
///
|
||||
/// Examples: database corruption, or the database is unavailable in an application that cannot
|
||||
/// function without it. Graphics environment cannot be initialized in a GUI app.
|
||||
///
|
||||
/// Applications should generally have only one FatalError type. There are no handling utilities
|
||||
/// for Fatal conditions, so Fatal conditions must be handled through an ordinary `match`
|
||||
/// statement.
|
||||
pub trait FatalError: Error {}
|
||||
|
||||
/// Flow<A, FE, E> represents a return value that might be a success, might be a fatal error, or
|
||||
/// might be a normal handleable error.
|
||||
pub enum Flow<A, FE, E> {
|
||||
/// The operation was successful
|
||||
Ok(A),
|
||||
/// The operation encountered a fatal error. These should be bubbled up to a level that can
|
||||
/// safely shut the application down.
|
||||
Fatal(FE),
|
||||
/// Ordinary errors. These should be handled and the application should recover gracefully.
|
||||
Err(E),
|
||||
}
|
||||
|
||||
impl<A, FE, E> Flow<A, FE, E> {
|
||||
/// Apply an infallible function to a successful value.
|
||||
pub fn map<B, O>(self, mapper: O) -> Flow<B, FE, E>
|
||||
where
|
||||
O: FnOnce(A) -> B,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(mapper(val)),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a potentially fallible function to a successful value.
|
||||
///
|
||||
/// Like `Result.and_then`, the mapping function can itself fail.
|
||||
pub fn and_then<B, O>(self, handler: O) -> Flow<B, FE, E>
|
||||
where
|
||||
O: FnOnce(A) -> Flow<B, FE, E>,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => handler(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Map a normal error from one type to another. This is useful for converting an error from
|
||||
/// one type to another, especially in re-throwing an underlying error. `?` syntax does not
|
||||
/// work with `Flow`, so you will likely need to use this a lot.
|
||||
pub fn map_err<F, O>(self, mapper: O) -> Flow<A, FE, F>
|
||||
where
|
||||
O: FnOnce(E) -> F,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(mapper(err)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Provide a function to use to recover from (or simply re-throw) an error.
|
||||
pub fn or_else<O, F>(self, handler: O) -> Flow<A, FE, F>
|
||||
where
|
||||
O: FnOnce(E) -> Flow<A, FE, F>,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => handler(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert from a normal `Result` type to a `Flow` type. The error condition for a `Result` will
|
||||
/// be treated as `Flow::Err`, never `Flow::Fatal`.
|
||||
impl<A, FE, E> From<Result<A, E>> for Flow<A, FE, E> {
|
||||
fn from(r: Result<A, E>) -> Self {
|
||||
match r {
|
||||
Ok(val) => Flow::Ok(val),
|
||||
Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience function to create an ok value.
|
||||
pub fn ok<A, FE: FatalError, E: Error>(val: A) -> Flow<A, FE, E> {
|
||||
Flow::Ok(val)
|
||||
}
|
||||
|
||||
/// Convenience function to create an error value.
|
||||
pub fn error<A, FE: FatalError, E: Error>(err: E) -> Flow<A, FE, E> {
|
||||
Flow::Err(err)
|
||||
}
|
||||
|
||||
/// Convenience function to create a fatal value.
|
||||
pub fn fatal<A, FE: FatalError, E: Error>(err: FE) -> Flow<A, FE, E> {
|
||||
Flow::Fatal(err)
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Return early from the current function if the value is a fatal error.
|
||||
macro_rules! return_fatal {
|
||||
($x:expr) => {
|
||||
match $x {
|
||||
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||
Flow::Err(err) => Err(err),
|
||||
Flow::Ok(val) => Ok(val),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Return early from the current function is the value is an error.
|
||||
macro_rules! return_error {
|
||||
($x:expr) => {
|
||||
match $x {
|
||||
Flow::Ok(val) => val,
|
||||
Flow::Err(err) => return Flow::Err(err),
|
||||
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum FatalError {
|
||||
#[error("A fatal error occurred")]
|
||||
FatalError,
|
||||
}
|
||||
impl super::FatalError for FatalError {}
|
||||
impl PartialEq for FatalError {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum Error {
|
||||
#[error("an error occurred")]
|
||||
Error,
|
||||
}
|
||||
impl PartialEq for Error {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Flow<i32, FatalError, Error> {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
match (self, rhs) {
|
||||
(Flow::Ok(val), Flow::Ok(rhs)) => val == rhs,
|
||||
(Flow::Err(_), Flow::Err(_)) => true,
|
||||
(Flow::Fatal(_), Flow::Fatal(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Flow<i32, FatalError, Error> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Flow::Ok(val) => f.write_fmt(format_args!("Flow::Ok {}", val)),
|
||||
Flow::Err(err) => f.write_fmt(format_args!("Flow::Err {:?}", err)),
|
||||
Flow::Fatal(err) => f.write_fmt(format_args!("Flow::Fatal {:?}", err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_map_things() {
|
||||
let success = ok(15);
|
||||
assert_eq!(ok(16), success.map(|v| v + 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_chain_success() {
|
||||
let success = ok(15);
|
||||
assert_eq!(ok(16), success.and_then(|v| ok(v + 1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_handle_an_error() {
|
||||
let failure = error(Error::Error);
|
||||
assert_eq!(ok(16), failure.or_else(|_| ok(16)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn early_exit_on_fatal() {
|
||||
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_fatal!(ok::<i32, FatalError, Error>(15));
|
||||
match value {
|
||||
Ok(_) => ok(14),
|
||||
Err(err) => error(err),
|
||||
}
|
||||
}
|
||||
|
||||
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_fatal!(error::<i32, FatalError, Error>(Error::Error));
|
||||
match value {
|
||||
Ok(_) => panic!("shouldn't have gotten here"),
|
||||
Err(err) => ok(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||
return_fatal!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fatal_func();
|
||||
assert_eq!(ok_func(), ok(14));
|
||||
assert_eq!(err_func(), ok(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_early_exit_on_all_errors() {
|
||||
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_error!(ok::<i32, FatalError, Error>(15));
|
||||
assert_eq!(value, 15);
|
||||
ok(14)
|
||||
}
|
||||
|
||||
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||
return_error!(error::<i32, FatalError, Error>(Error::Error));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||
return_error!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fatal_func();
|
||||
assert_eq!(ok_func(), ok(14));
|
||||
err_func();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,8 @@ authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
|||
edition = "2018"
|
||||
version = "0.2.0"
|
||||
description = "An ergonomics wrapper around Fluent-RS"
|
||||
license = "AGPL-3.0-or-later"
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
homepage = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
||||
repository = "https://github.com/luminescent-dreams/fluent-ergonomics"
|
||||
categories = ["internationalization"]
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//! Provide a more ergonomic interface to the base Fluent library
|
||||
//!
|
||||
//! The Fluent class makes it easier to load translation bundles with language fallbacks and to go
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
name = "hex-grid"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ authors = ["Savanni D'Gerinel <savanni@luminescent-dreams.com>"]
|
|||
edition = "2018"
|
||||
keywords = ["date", "time", "calendar"]
|
||||
categories = ["date-and-time"]
|
||||
license = "GPL-3.0-only"
|
||||
license-file = "../COPYING"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate chrono;
|
||||
extern crate chrono_tz;
|
||||
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
extern crate chrono;
|
||||
extern crate chrono_tz;
|
||||
extern crate international_fixed_calendar as IFC;
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
/*
|
||||
Copyright 2020-2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use chrono::{Datelike, Utc};
|
||||
use international_fixed_calendar as IFC;
|
||||
use iron::headers;
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="./styles.css" type="text/css" />
|
||||
<title>Music Player</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="currently-playing"> <span class="track-title"> Lindsey Sterling - Elements </span> <span class="player-status">[paused]</span> </div>
|
||||
<div class="controls"><button class="play-pause">Pause</button></div>
|
||||
|
||||
<div class="track-list">
|
||||
<div class="track-list__grouping">
|
||||
<ul class="bulletless-list">
|
||||
<li> By Artist </li>
|
||||
<li> By Album </li>
|
||||
<li> Work Music </li>
|
||||
<li> Dance Music </li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="track-list__tracks">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th> Track # </th>
|
||||
<th> Title </th>
|
||||
<th> Artist </th>
|
||||
<th> Album </th>
|
||||
<th> Length </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 1 </td>
|
||||
<td> Underground </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:24 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 2 </td>
|
||||
<td> Artemis </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 3:54 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 3 </td>
|
||||
<td> Til the Light Goes Out </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:46 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 4 </td>
|
||||
<td> Between Twilight </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:20 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 5 </td>
|
||||
<td> Foreverglow </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 3:58 </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="./dist/main.js" type="module"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "music-player-client",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"build": "browserify src/main.ts -p [ tsify ] > dist/bundle.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "exa index.html styles.css src/* | entr -s 'npm run build'"
|
||||
},
|
||||
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21",
|
||||
"systemjs": "^6.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.191",
|
||||
"babelify": "^10.0.0",
|
||||
"browserify": "^17.0.0",
|
||||
"live-server": "^1.2.2",
|
||||
"tsify": "^5.0.4",
|
||||
"typescript": "^4.9.4",
|
||||
"watchify": "^4.0.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import * as _ from "lodash";
|
||||
|
||||
const replaceTitle = () => {
|
||||
const title = document.querySelector(".js-title");
|
||||
if (title && title.innerHTML) {
|
||||
title.innerHTML = "Music Player Paused";
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
const checkWeatherService = () => {
|
||||
fetch("https://api.weather.gov/")
|
||||
.then((r) => r.json())
|
||||
.then((js) => {
|
||||
const weather = document.querySelector('.js-weather');
|
||||
weather.innerHTML = js.status;
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
const run = () => {
|
||||
replaceTitle();
|
||||
console.log(_.map([4, 8], (x) => x * x));
|
||||
// checkWeatherService();
|
||||
};
|
||||
|
||||
run();
|
|
@ -0,0 +1,39 @@
|
|||
body {
|
||||
background-color: rgb(240, 230, 230);
|
||||
}
|
||||
|
||||
.currently-playing {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.track-list {
|
||||
border: 1px solid black;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.track-list__grouping {
|
||||
padding: 8px;
|
||||
border-style: solid;
|
||||
border-width: 0px 5px 0px 0px;
|
||||
}
|
||||
|
||||
.bulletless-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.track-list__track-row {
|
||||
background-color: rgb(10, 10, 10);
|
||||
}
|
||||
|
||||
.track-list__track-row:nth-child(even) {
|
||||
background-color: rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
.track-list__track-row:nth-child(odd) {
|
||||
background-color: rgb(200, 200, 200);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"rootDir": "src",
|
||||
"outDir": "./dist",
|
||||
"lib": ["es2016", "DOM"],
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
pub use flow::error;
|
||||
|
||||
pub enum FatalError {
|
||||
UnexpectedError,
|
||||
}
|
||||
|
||||
impl flow::FatalError for FatalError {}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "music-player"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dbus = { version = "0.9.7" }
|
||||
flow = { path = "../../flow" }
|
||||
mpris = { version = "2.0" }
|
||||
rusqlite = { version = "0.28" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = { version = "1.0" }
|
||||
tokio = { version = "1.24", features = ["full"] }
|
||||
url = { version = "2.3" }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
warp = { version = "0.3" }
|
||||
|
||||
[lib]
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use dbus::ffidisp::Connection;
|
||||
use mpris::{FindingError, PlaybackStatus, Player, PlayerFinder, ProgressTick};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::mpsc::{channel, Receiver, Sender, TryRecvError},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
pub enum Message {
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Event {
|
||||
Paused(Track, Duration),
|
||||
Playing(Track, Duration),
|
||||
Stopped,
|
||||
Position(Track, Duration),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceInformation {
|
||||
pub address: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub fn list_devices(conn: Connection) -> Result<Vec<DeviceInformation>, FindingError> {
|
||||
Ok(PlayerFinder::for_connection(conn)
|
||||
.find_all()?
|
||||
.into_iter()
|
||||
.map(|player| DeviceInformation {
|
||||
address: player.unique_name().to_owned(),
|
||||
name: player.identity().to_owned(),
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AudioError {
|
||||
#[error("DBus device was not found")]
|
||||
DeviceNotFound,
|
||||
|
||||
#[error("DBus connection lost or otherwise failed")]
|
||||
ConnectionLost,
|
||||
|
||||
#[error("Specified media cannot be found")]
|
||||
MediaNotFound,
|
||||
|
||||
#[error("Play was ordered, but nothing is in the queue")]
|
||||
NothingInQueue,
|
||||
|
||||
#[error("Unknown dbus error")]
|
||||
DbusError(dbus::Error),
|
||||
|
||||
#[error("Unknown problem with mpris")]
|
||||
MprisError(mpris::DBusError),
|
||||
|
||||
#[error("url parse error {0}")]
|
||||
UrlError(url::ParseError),
|
||||
}
|
||||
|
||||
impl From<dbus::Error> for AudioError {
|
||||
fn from(err: dbus::Error) -> Self {
|
||||
Self::DbusError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mpris::DBusError> for AudioError {
|
||||
fn from(err: mpris::DBusError) -> Self {
|
||||
Self::MprisError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<url::ParseError> for AudioError {
|
||||
fn from(err: url::ParseError) -> Self {
|
||||
Self::UrlError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct TrackId(String);
|
||||
|
||||
impl Default for TrackId {
|
||||
fn default() -> Self {
|
||||
Self(uuid::Uuid::new_v4().as_hyphenated().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for TrackId {
|
||||
fn from(id: String) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<String> for TrackId {
|
||||
fn as_ref<'a>(&'a self) -> &'a String {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TrackInfo {
|
||||
pub track_number: Option<i32>,
|
||||
pub name: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub artist: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Track {
|
||||
pub id: TrackId,
|
||||
pub track_number: Option<i32>,
|
||||
pub name: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub artist: Option<String>,
|
||||
}
|
||||
|
||||
/*
|
||||
impl From<&mpris::Metadata> for Track {
|
||||
fn from(data: &mpris::Metadata) -> Self {
|
||||
Self {
|
||||
id: data.track_id().unwrap(),
|
||||
track_number: data.track_number(),
|
||||
name: data.title().map(|s| s.to_owned()),
|
||||
album: data.album_name().map(|s| s.to_owned()),
|
||||
artist: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mpris::Metadata> for Track {
|
||||
fn from(data: mpris::Metadata) -> Self {
|
||||
Self::from(&data)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum State {
|
||||
Playing(Track),
|
||||
Paused(Track),
|
||||
Stopped,
|
||||
}
|
||||
|
||||
pub struct CurrentlyPlaying {
|
||||
track: Track,
|
||||
position: Duration,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Capabilities {
|
||||
pub can_control: bool,
|
||||
pub can_pause: bool,
|
||||
pub can_play: bool,
|
||||
pub supports_track_lists: bool,
|
||||
}
|
||||
|
||||
pub trait AudioPlayer {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError>;
|
||||
fn state(&self) -> Result<State, AudioError>;
|
||||
fn play(&self, trackid: url::Url) -> Result<State, AudioError>;
|
||||
fn play_pause(&self) -> Result<State, AudioError>;
|
||||
}
|
||||
|
||||
pub struct GStreamerPlayer {
|
||||
url: url::Url,
|
||||
}
|
||||
|
||||
impl AudioPlayer for GStreamerPlayer {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn state(&self) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn play(&self, trackid: url::Url) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn play_pause(&self) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub struct MprisDevice {
|
||||
device_id: String,
|
||||
player: Player,
|
||||
state: State,
|
||||
}
|
||||
|
||||
impl MprisDevice {
|
||||
pub fn new(device_id: String) -> Result<MprisDevice, AudioError> {
|
||||
let connection = Connection::new_session()?;
|
||||
Ok(MprisDevice {
|
||||
device_id: device_id.clone(),
|
||||
player: mpris::Player::new(connection, device_id, 1000)?,
|
||||
state: State::Stopped,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn monitor(&mut self, control_channel: Receiver<Message>) {
|
||||
let (tx, rx) = channel();
|
||||
{
|
||||
let device_id = self.device_id.clone();
|
||||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
MprisDevice::new(device_id)
|
||||
.expect("connect to bus")
|
||||
.monitor_progress(tx);
|
||||
});
|
||||
};
|
||||
|
||||
loop {
|
||||
match control_channel.try_recv() {
|
||||
Ok(Message::Quit) => return,
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => return,
|
||||
}
|
||||
let event = rx.recv().expect("receive should never fail");
|
||||
println!("event received: {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn monitor_progress(&self, tx: Sender<Event>) {
|
||||
let mut tracker = self
|
||||
.player
|
||||
.track_progress(1000)
|
||||
.expect("can get an event stream");
|
||||
loop {
|
||||
let ProgressTick { progress, .. } = tracker.tick();
|
||||
match progress.playback_status() {
|
||||
PlaybackStatus::Playing => {
|
||||
tx.send(Event::Playing(
|
||||
Track::from(progress.metadata()),
|
||||
progress.position(),
|
||||
))
|
||||
.expect("send to succeed");
|
||||
}
|
||||
PlaybackStatus::Paused => {
|
||||
tx.send(Event::Paused(
|
||||
Track::from(progress.metadata()),
|
||||
progress.position(),
|
||||
))
|
||||
.expect("send to succeed");
|
||||
}
|
||||
PlaybackStatus::Stopped => {
|
||||
tx.send(Event::Stopped).expect("send to succeed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioPlayer for MprisDevice {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError> {
|
||||
Ok(Capabilities {
|
||||
can_control: self.player.can_control()?,
|
||||
can_pause: self.player.can_pause()?,
|
||||
can_play: self.player.can_play()?,
|
||||
supports_track_lists: self.player.supports_track_lists(),
|
||||
})
|
||||
}
|
||||
|
||||
fn state(&self) -> Result<State, AudioError> {
|
||||
println!(
|
||||
"supports track lists: {:?}",
|
||||
self.player.supports_track_lists()
|
||||
);
|
||||
let metadata = self.player.get_metadata()?;
|
||||
println!("{:?}", metadata);
|
||||
unimplemented!("AudioPlayer state")
|
||||
}
|
||||
|
||||
fn play(&self, track_id: String) -> Result<State, AudioError> {
|
||||
println!("playing: {}", track_id);
|
||||
self.player
|
||||
.go_to(&mpris::TrackID::from(dbus::Path::from(track_id)))?;
|
||||
self.player.play();
|
||||
Ok(State::Stopped)
|
||||
}
|
||||
|
||||
fn play_pause(&self) -> Result<State, AudioError> {
|
||||
self.player.play_pause()?;
|
||||
Ok(State::Stopped)
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,114 @@
|
|||
use flow::Flow;
|
||||
use std::{io::stdin, path::PathBuf, sync::Arc, thread, time::Duration};
|
||||
// use warp::Filter;
|
||||
|
||||
use music_player::{core::Core, database::MemoryIndex};
|
||||
|
||||
/*
|
||||
fn tracks() -> Vec<Track> {
|
||||
vec![
|
||||
Track {
|
||||
track_number: Some(1),
|
||||
name: Some("Underground".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/01 - Underground.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(2),
|
||||
name: Some("Artemis".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/02 - Artemis.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(3),
|
||||
name: Some("Til the Light Goes Out".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from(
|
||||
"/mnt/music/Lindsey Stirling/Artemis/03 - Til the Light Goes Out.ogg",
|
||||
),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(4),
|
||||
name: Some("Between Twilight".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/04 - Between Twilight.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(5),
|
||||
name: Some("Foreverglow".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/05 - Foreverglow.ogg"),
|
||||
},
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
match Core::new(Arc::new(MemoryIndex::new())) {
|
||||
Flow::Ok(core) => {
|
||||
let mut buf = String::new();
|
||||
let _ = stdin().read_line(&mut buf).unwrap();
|
||||
core.exit();
|
||||
}
|
||||
Flow::Err(err) => println!("non-fatal error: {:?}", err),
|
||||
Flow::Fatal(err) => println!("fatal error: {:?}", err),
|
||||
}
|
||||
|
||||
/*
|
||||
let connection = Connection::new_session().expect("to connect to dbus");
|
||||
|
||||
for player in list_players(connection) {
|
||||
println!("player found: {}", player.identity());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
let devices = warp::path!("api" / "v1" / "devices")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let conn = Connection::new_session().expect("to connect to dbus");
|
||||
warp::reply::json(&list_devices(conn))
|
||||
});
|
||||
|
||||
let track_list = warp::path!("api" / "v1" / "tracks")
|
||||
.and(warp::get())
|
||||
.map(|| warp::reply::json(&tracks()));
|
||||
let tracks_for_artist = warp::path!("api" / "v1" / "artist" / String)
|
||||
.and(warp::get())
|
||||
.map(|_artist: String| warp::reply::json(&tracks()));
|
||||
let tracks_for_album = warp::path!("api" / "v1" / "album" / String)
|
||||
.and(warp::get())
|
||||
.map(|_album: String| warp::reply::json(&tracks()));
|
||||
|
||||
let queue = warp::path!("api" / "v1" / "queue")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let conn = Connection::new_session().expect("to connect to dbus");
|
||||
warp::reply::json(&list_tracks(conn))
|
||||
});
|
||||
|
||||
let playing_status = warp::path!("api" / "v1" / "play-pause")
|
||||
.and(warp::get())
|
||||
.map(|| warp::reply::json(&PlayPause::Paused));
|
||||
|
||||
let routes = devices
|
||||
.or(track_list)
|
||||
.or(tracks_for_album)
|
||||
.or(tracks_for_artist)
|
||||
.or(queue)
|
||||
.or(playing_status);
|
||||
let server = warp::serve(routes);
|
||||
server
|
||||
.run(SocketAddr::new(
|
||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
8002,
|
||||
))
|
||||
.await;
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
use crate::{
|
||||
database::{Database, MemoryIndex, MusicIndex},
|
||||
Error, FatalError,
|
||||
};
|
||||
use flow::{error, fatal, ok, return_error, return_fatal, Flow};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
||||
Arc,
|
||||
},
|
||||
thread,
|
||||
thread::JoinHandle,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ScannerError {
|
||||
#[error("Cannot scan {0}")]
|
||||
CannotScan(PathBuf),
|
||||
#[error("IO error {0}")]
|
||||
IO(std::io::Error),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ScannerError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self::IO(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ControlMsg {
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub enum TrackMsg {
|
||||
DbUpdate,
|
||||
}
|
||||
|
||||
pub enum PlaybackMsg {
|
||||
PositionUpdate,
|
||||
Playing,
|
||||
Pausing,
|
||||
Stopping,
|
||||
}
|
||||
|
||||
pub struct Core {
|
||||
db: Arc<dyn MusicIndex>,
|
||||
track_handle: JoinHandle<()>,
|
||||
track_rx: Receiver<TrackMsg>,
|
||||
playback_handle: JoinHandle<()>,
|
||||
playback_rx: Receiver<PlaybackMsg>,
|
||||
control_tx: Sender<ControlMsg>,
|
||||
}
|
||||
|
||||
fn scan_frequency() -> Duration {
|
||||
Duration::from_secs(60)
|
||||
}
|
||||
|
||||
pub struct FileScanner {
|
||||
db: Arc<dyn MusicIndex>,
|
||||
control_rx: Receiver<ControlMsg>,
|
||||
tracker_tx: Sender<TrackMsg>,
|
||||
next_scan: Instant,
|
||||
music_directories: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl FileScanner {
|
||||
fn new(
|
||||
db: Arc<dyn MusicIndex>,
|
||||
roots: Vec<PathBuf>,
|
||||
control_rx: Receiver<ControlMsg>,
|
||||
tracker_tx: Sender<TrackMsg>,
|
||||
) -> Self {
|
||||
Self {
|
||||
db,
|
||||
control_rx,
|
||||
tracker_tx,
|
||||
next_scan: Instant::now(),
|
||||
music_directories: roots,
|
||||
}
|
||||
}
|
||||
|
||||
fn scan(&mut self) {
|
||||
loop {
|
||||
match self.control_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(ControlMsg::Exit) => return,
|
||||
Err(RecvTimeoutError::Timeout) => (),
|
||||
Err(RecvTimeoutError::Disconnected) => return,
|
||||
}
|
||||
if Instant::now() >= self.next_scan {
|
||||
for root in self.music_directories.iter() {
|
||||
self.scan_dir(vec![root.clone()]);
|
||||
}
|
||||
self.next_scan = Instant::now() + scan_frequency();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_dir(&self, mut paths: Vec<PathBuf>) -> Flow<(), FatalError, ScannerError> {
|
||||
while let Some(dir) = paths.pop() {
|
||||
println!("scanning {:?}", dir);
|
||||
return_error!(self.scan_dir_(&mut paths, dir));
|
||||
}
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn scan_dir_(
|
||||
&self,
|
||||
paths: &mut Vec<PathBuf>,
|
||||
dir: PathBuf,
|
||||
) -> Flow<(), FatalError, ScannerError> {
|
||||
let dir_iter = return_error!(Flow::from(dir.read_dir().map_err(ScannerError::from)));
|
||||
for entry in dir_iter {
|
||||
match entry {
|
||||
Ok(entry) if entry.path().is_dir() => paths.push(entry.path()),
|
||||
Ok(entry) => {
|
||||
let _ = return_fatal!(self.scan_file(entry.path()).or_else(|err| {
|
||||
println!("scan_file failed: {:?}", err);
|
||||
ok::<(), FatalError, ScannerError>(())
|
||||
}));
|
||||
()
|
||||
}
|
||||
Err(err) => {
|
||||
println!("scan_dir could not read path: ({:?})", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn scan_file(&self, path: PathBuf) -> Flow<(), FatalError, ScannerError> {
|
||||
ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Core {
|
||||
pub fn new(db: Arc<dyn MusicIndex>) -> Flow<Core, FatalError, Error> {
|
||||
let (control_tx, control_rx) = channel::<ControlMsg>();
|
||||
|
||||
let (track_handle, track_rx) = {
|
||||
let (track_tx, track_rx) = channel();
|
||||
let db = db.clone();
|
||||
let track_handle = thread::spawn(move || {
|
||||
FileScanner::new(
|
||||
db,
|
||||
vec![PathBuf::from("/home/savanni/Music/")],
|
||||
control_rx,
|
||||
track_tx,
|
||||
)
|
||||
.scan();
|
||||
});
|
||||
(track_handle, track_rx)
|
||||
};
|
||||
|
||||
let (playback_handle, playback_rx) = {
|
||||
let (playback_tx, playback_rx) = channel();
|
||||
let playback_handle = thread::spawn(move || {});
|
||||
(playback_handle, playback_rx)
|
||||
};
|
||||
|
||||
ok(Core {
|
||||
db,
|
||||
track_handle,
|
||||
track_rx,
|
||||
playback_handle,
|
||||
playback_rx,
|
||||
control_tx,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
let _ = self.control_tx.send(ControlMsg::Exit);
|
||||
/*
|
||||
self.track_handle.join();
|
||||
self.playback_handle.join();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
|
@ -0,0 +1,106 @@
|
|||
use crate::{
|
||||
audio::{Track, TrackId, TrackInfo},
|
||||
FatalError,
|
||||
};
|
||||
use flow::{error, ok, Flow};
|
||||
use rusqlite::Connection;
|
||||
use std::collections::HashMap;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DatabaseError {
|
||||
#[error("database is unreadable")]
|
||||
DatabaseUnreadable,
|
||||
#[error("unhandled database problem: {0}")]
|
||||
UnhandledError(rusqlite::Error),
|
||||
}
|
||||
|
||||
pub trait MusicIndex: Sync + Send {
|
||||
fn add_track(&mut self, track: &TrackInfo) -> Flow<Track, FatalError, DatabaseError>;
|
||||
fn remove_track(&mut self, id: &TrackId) -> Flow<(), FatalError, DatabaseError>;
|
||||
fn get_track_info(&self, id: &TrackId) -> Flow<Option<Track>, FatalError, DatabaseError>;
|
||||
}
|
||||
|
||||
pub struct MemoryIndex {
|
||||
tracks: RwLock<HashMap<TrackId, Track>>,
|
||||
}
|
||||
|
||||
impl MemoryIndex {
|
||||
pub fn new() -> MemoryIndex {
|
||||
MemoryIndex {
|
||||
tracks: RwLock::new(HashMap::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MusicIndex for MemoryIndex {
|
||||
fn add_track(&mut self, info: &TrackInfo) -> Flow<Track, FatalError, DatabaseError> {
|
||||
let id = TrackId::default();
|
||||
let track = Track {
|
||||
id: id.clone(),
|
||||
track_number: info.track_number,
|
||||
name: info.name.clone(),
|
||||
album: info.album.clone(),
|
||||
artist: info.artist.clone(),
|
||||
};
|
||||
let mut tracks = self.tracks.write().unwrap();
|
||||
tracks.insert(id, track.clone());
|
||||
ok(track)
|
||||
}
|
||||
|
||||
fn remove_track(&mut self, id: &TrackId) -> Flow<(), FatalError, DatabaseError> {
|
||||
let mut tracks = self.tracks.write().unwrap();
|
||||
tracks.remove(&id);
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn get_track_info<'a>(
|
||||
&'a self,
|
||||
id: &TrackId,
|
||||
) -> Flow<Option<Track>, FatalError, DatabaseError> {
|
||||
let track = {
|
||||
let tracks = self.tracks.read().unwrap();
|
||||
tracks.get(&id).cloned()
|
||||
};
|
||||
ok(track)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ManagedConnection<'a> {
|
||||
pool: &'a Database,
|
||||
conn: Option<Connection>,
|
||||
}
|
||||
|
||||
impl<'a> Drop for ManagedConnection<'a> {
|
||||
fn drop(&mut self) {
|
||||
self.pool.r(self.conn.take().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
path: PathBuf,
|
||||
pool: Arc<Mutex<Vec<Connection>>>,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new(path: PathBuf) -> Flow<Database, FatalError, DatabaseError> {
|
||||
let connection = match Connection::open(path.clone()) {
|
||||
Ok(connection) => connection,
|
||||
Err(err) => return error(DatabaseError::UnhandledError(err)),
|
||||
};
|
||||
ok(Database {
|
||||
path,
|
||||
pool: Arc::new(Mutex::new(vec![connection])),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn r(&self, conn: Connection) {
|
||||
let mut pool = self.pool.lock().unwrap();
|
||||
pool.push(conn);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
pub mod audio;
|
||||
pub mod core;
|
||||
pub mod database;
|
||||
use database::DatabaseError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("Database error: {0}")]
|
||||
DatabaseError(DatabaseError),
|
||||
}
|
||||
|
||||
impl From<DatabaseError> for Error {
|
||||
fn from(err: DatabaseError) -> Self {
|
||||
Self::DatabaseError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FatalError {
|
||||
#[error("Unexpected error")]
|
||||
UnexpectedError,
|
||||
}
|
||||
|
||||
impl flow::FatalError for FatalError {}
|
|
@ -0,0 +1,514 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-expr"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0357a6402b295ca3a86bc148e84df46c02e41f41fef186bda662557ef6328aa"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gio-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9b693b8e39d042a95547fc258a7b07349b1f0b48f4b2fa3108ba3c51c0b5229"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib"
|
||||
version = "0.16.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd4df61a866ed7259d6189b8bcb1464989a77f1d85d25d002279bbe9dd38b2f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
"gio-sys",
|
||||
"glib-macros",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-macros"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e084807350b01348b6d9dbabb724d1a0bb987f47a2c85de200e98e12e30733bf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"proc-macro-crate",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61a4f46316d06bfa33a7ac22df6f0524c8be58e3db2d9ca99ccb1f357b62a65"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gobject-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3520bb9c07ae2a12c7f2fbb24d4efc11231c8146a86956413fb1a79bb760a0f1"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer"
|
||||
version = "0.19.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61af131b56332ec386a8ea538d961d0c6937054fb2771a9a505395f8471b7b0e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"glib",
|
||||
"gstreamer-sys",
|
||||
"libc",
|
||||
"muldiv",
|
||||
"num-integer",
|
||||
"num-rational",
|
||||
"once_cell",
|
||||
"option-operations",
|
||||
"paste",
|
||||
"pretty-hex",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-sys"
|
||||
version = "0.19.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "545f52ad8a480732cc4290fd65dfe42952c8ae374fe581831ba15981fedf18a4"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "muldiv"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
|
||||
|
||||
[[package]]
|
||||
name = "nom8"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "option-operations"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c26d27bb1aeab65138e4bf7666045169d1717febcc9ff870166be8348b223d0"
|
||||
dependencies = [
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "pretty-hex"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||
|
||||
[[package]]
|
||||
name = "streamer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gstreamer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2955b1fe31e1fa2fbd1976b71cc69a606d7d4da16f6de3333d0c92d51419aeff"
|
||||
dependencies = [
|
||||
"cfg-expr",
|
||||
"heck",
|
||||
"pkg-config",
|
||||
"toml",
|
||||
"version-compare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"nom8",
|
||||
"toml_datetime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "streamer"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gstreamer = "0.19.7"
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
use gstreamer::{format::ClockTime, prelude::*, MessageView};
|
||||
use std::{thread, time, time::Duration};
|
||||
|
||||
fn main() {
|
||||
gstreamer::init().unwrap();
|
||||
|
||||
let uri = "file:///home/savanni/Music/Lindsey%20Stirling/Artemis/01%20-%20Underground.mp3.mp3";
|
||||
let pipeline = gstreamer::parse_launch(&format!("playbin uri={}", uri)).unwrap();
|
||||
pipeline.set_state(gstreamer::State::Playing).unwrap();
|
||||
|
||||
let message_handler = {
|
||||
let pipeline = pipeline.clone();
|
||||
thread::spawn(move || {
|
||||
let bus = pipeline.bus().unwrap();
|
||||
for msg in bus.iter_timed(gstreamer::ClockTime::NONE) {
|
||||
match msg.view() {
|
||||
MessageView::Eos(_) => (),
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
"Error from {:?}: {} ({:?})",
|
||||
err.src().map(|s| s.path_string()),
|
||||
err.error(),
|
||||
err.debug()
|
||||
);
|
||||
}
|
||||
msg => println!("{:?}", msg),
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let query_handler = {
|
||||
let pipeline = pipeline.clone();
|
||||
thread::spawn(move || loop {
|
||||
let position: Option<ClockTime> = pipeline.query_position();
|
||||
let duration: Option<ClockTime> = pipeline.query_duration();
|
||||
println!("{:?} {:?}", position, duration);
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
})
|
||||
};
|
||||
|
||||
message_handler.join();
|
||||
query_handler.join();
|
||||
|
||||
pipeline.set_state(gstreamer::State::Null).unwrap();
|
||||
}
|
Loading…
Reference in New Issue