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:
savanni 2023-02-11 17:59:15 +00:00
parent cca1b9c3ba
commit e60a2fbc30
44 changed files with 12380 additions and 23 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
target
.direnv/
node_modules
dist

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -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/

View File

@ -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"

View File

@ -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,

View File

@ -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;

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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"
}
}
},

View File

@ -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";
};
};
}

65
flow/Cargo.lock generated Normal file
View File

@ -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"

11
flow/Cargo.toml Normal file
View File

@ -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"

3
flow/readme.md Normal file
View File

@ -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.

257
flow/src/lib.rs Normal file
View File

@ -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();
}
}

View File

@ -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"]

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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>

8976
music-player/client/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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"
}
}

View File

@ -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();

View File

@ -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);
}

View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "src",
"outDir": "./dist",
"lib": ["es2016", "DOM"],
"sourceMap": true
}
}

7
music-player/errors.rs Normal file
View File

@ -0,0 +1,7 @@
pub use flow::error;
pub enum FatalError {
UnexpectedError,
}
impl flow::FatalError for FatalError {}

1334
music-player/server/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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]

View File

@ -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,