From 01622734eb5a8d4af9edd4b113815d8bbdd6b544 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 14:35:44 +0100 Subject: [PATCH 1/7] media/util/serato: Move color conversion into separate function --- media/src/util/serato.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 017a59ea..48031fda 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -23,17 +23,18 @@ use aoide_core::{ CanonicalizeInto as _, }, }; -use triseratops::tag::TagContainer; +use triseratops::tag::{generic::Color as SeratoColor, TagContainer}; + +fn color_to_rgb(color: &SeratoColor) -> Color { + let color_code = (color.red as u32) << 16 | (color.green as u32) << 8 | color.blue as u32; + Color::Rgb(RgbColor(color_code)) +} /// Return a canonical vector of cues found in the tag container. pub fn read_cues(serato_tags: &TagContainer) -> Result> { let mut track_cues = vec![]; for serato_cue in serato_tags.cues() { - let color_code = (serato_cue.color.red as u32) << 16 - | (serato_cue.color.green as u32) << 8 - | serato_cue.color.blue as u32; - let cue = Cue { bank_index: 0, slot_index: Some(serato_cue.index.into()), @@ -41,7 +42,7 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { out_position: None, out_mode: None, label: Some(serato_cue.label), - color: Some(Color::Rgb(RgbColor(color_code))), + color: Some(color_to_rgb(&serato_cue.color)), flags: CueFlags::empty(), }; track_cues.push(cue); -- GitLab From 139dd146c954d10040525367fb9bc77c9bdb6a9a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 14:36:14 +0100 Subject: [PATCH 2/7] media: Add support for importing serato track color --- media/src/fmt/flac/mod.rs | 2 ++ media/src/fmt/mp3/mod.rs | 2 ++ media/src/fmt/mp4/mod.rs | 2 ++ media/src/fmt/ogg/mod.rs | 2 ++ media/src/util/serato.rs | 7 +++++++ 5 files changed, 15 insertions(+) diff --git a/media/src/fmt/flac/mod.rs b/media/src/fmt/flac/mod.rs index cb47f642..98a283e5 100644 --- a/media/src/fmt/flac/mod.rs +++ b/media/src/fmt/flac/mod.rs @@ -302,6 +302,8 @@ impl import::ImportTrack for ImportTrack { if !track_cues.is_empty() { track.cues = Canonical::tie(track_cues); } + + track.color = serato::read_track_color(&serato_tags); } Ok(track) diff --git a/media/src/fmt/mp3/mod.rs b/media/src/fmt/mp3/mod.rs index 8219b379..fdc0f369 100644 --- a/media/src/fmt/mp3/mod.rs +++ b/media/src/fmt/mp3/mod.rs @@ -558,6 +558,8 @@ impl import::ImportTrack for ImportTrack { if !track_cues.is_empty() { track.cues = Canonical::tie(track_cues); } + + track.color = serato::read_track_color(&serato_tags); } Ok(track) diff --git a/media/src/fmt/mp4/mod.rs b/media/src/fmt/mp4/mod.rs index 5ff0f8ff..419e52d4 100644 --- a/media/src/fmt/mp4/mod.rs +++ b/media/src/fmt/mp4/mod.rs @@ -488,6 +488,8 @@ impl import::ImportTrack for ImportTrack { if !track_cues.is_empty() { track.cues = Canonical::tie(track_cues); } + + track.color = serato::read_track_color(&serato_tags); } Ok(track) diff --git a/media/src/fmt/ogg/mod.rs b/media/src/fmt/ogg/mod.rs index 1acaab8c..17fb6406 100644 --- a/media/src/fmt/ogg/mod.rs +++ b/media/src/fmt/ogg/mod.rs @@ -332,6 +332,8 @@ impl import::ImportTrack for ImportTrack { if !track_cues.is_empty() { track.cues = Canonical::tie(track_cues); } + + track.color = serato::read_track_color(&serato_tags); } Ok(track) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 48031fda..735cf668 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -70,3 +70,10 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { let track_cues = track_cues.canonicalize_into(); Ok(track_cues) } + +pub fn read_track_color(serato_tags: &TagContainer) -> Option { + match serato_tags.track_color() { + Some(color) => Some(color_to_rgb(&color)), + None => None, + } +} -- GitLab From 751b2a733b24ae193bc58ff4a8d2982be3ad20db Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 18:26:19 +0100 Subject: [PATCH 3/7] media/util/serato: Remove obsolete color_to_rgb function --- Cargo.lock | 2 +- Cargo.toml | 2 +- media/src/util/serato.rs | 11 +++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9870bb81..b6b3c161 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2108,7 +2108,7 @@ dependencies = [ [[package]] name = "triseratops" version = "0.0.1" -source = "git+https://github.com/Holzhaus/triseratops.git?rev=9b71e26f59d15ffe771090c5918cf150ebc7f5c5#9b71e26f59d15ffe771090c5918cf150ebc7f5c5" +source = "git+https://github.com/Holzhaus/triseratops.git?rev=3744aa23862de19999df2a5098a887315298a760#3744aa23862de19999df2a5098a887315298a760" dependencies = [ "base64", "nom", diff --git a/Cargo.toml b/Cargo.toml index f6577eae..fa3e990f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ aoide-core-serde = { path = "core-serde" } aoide-media = { path = "media" } aoide-repo = { path = "repo" } aoide-repo-sqlite = { path = "repo-sqlite" } -triseratops = { rev = "9b71e26f59d15ffe771090c5918cf150ebc7f5c5", git = "https://github.com/Holzhaus/triseratops.git" } +triseratops = { rev = "3744aa23862de19999df2a5098a887315298a760", git = "https://github.com/Holzhaus/triseratops.git" } #mp4ameta = { branch = "master", git = "https://github.com/Saecki/rust-mp4ameta.git" } #id3 = { branch = "master", git = "https://github.com/polyfloyd/rust-id3.git" } diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 735cf668..4f1bc293 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -23,12 +23,7 @@ use aoide_core::{ CanonicalizeInto as _, }, }; -use triseratops::tag::{generic::Color as SeratoColor, TagContainer}; - -fn color_to_rgb(color: &SeratoColor) -> Color { - let color_code = (color.red as u32) << 16 | (color.green as u32) << 8 | color.blue as u32; - Color::Rgb(RgbColor(color_code)) -} +use triseratops::tag::TagContainer; /// Return a canonical vector of cues found in the tag container. pub fn read_cues(serato_tags: &TagContainer) -> Result> { @@ -42,7 +37,7 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { out_position: None, out_mode: None, label: Some(serato_cue.label), - color: Some(color_to_rgb(&serato_cue.color)), + color: Some(Color::Rgb(RgbColor(serato_cue.color.into()))), flags: CueFlags::empty(), }; track_cues.push(cue); @@ -73,7 +68,7 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { pub fn read_track_color(serato_tags: &TagContainer) -> Option { match serato_tags.track_color() { - Some(color) => Some(color_to_rgb(&color)), + Some(color) => Some(Color::Rgb(RgbColor(color.into()))), None => None, } } -- GitLab From c9830e79f6ef19f788af98becf54c2fd8d64c1d2 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 18:36:25 +0100 Subject: [PATCH 4/7] media/util/serato: Convert stored track color into library track color --- media/src/util/serato.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 4f1bc293..ab78eff2 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -67,7 +67,12 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { } pub fn read_track_color(serato_tags: &TagContainer) -> Option { - match serato_tags.track_color() { + let track_color = match serato_tags.track_color() { + Some(color) => color.into_displayed_track_color(), + None => None, + }; + + match track_color { Some(color) => Some(Color::Rgb(RgbColor(color.into()))), None => None, } -- GitLab From 5feb281bd530baabf4f95b1a502ebe6592d8de5e Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 18:37:10 +0100 Subject: [PATCH 5/7] media/util/serato: Convert metadata hotcue color into Pro track color --- media/src/util/serato.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index ab78eff2..547d7f26 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -37,7 +37,9 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { out_position: None, out_mode: None, label: Some(serato_cue.label), - color: Some(Color::Rgb(RgbColor(serato_cue.color.into()))), + color: Some(Color::Rgb(RgbColor( + serato_cue.color.into_pro_hotcue_color().into(), + ))), flags: CueFlags::empty(), }; track_cues.push(cue); -- GitLab From 8caa570c43f70483b56f0144a98119ddb35930d1 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 11 Feb 2021 22:41:15 +0100 Subject: [PATCH 6/7] media/util/serato: Clean up read_track_color() code --- media/src/util/serato.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 547d7f26..92a973e5 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -69,13 +69,11 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { } pub fn read_track_color(serato_tags: &TagContainer) -> Option { - let track_color = match serato_tags.track_color() { - Some(color) => color.into_displayed_track_color(), - None => None, - }; - - match track_color { - Some(color) => Some(Color::Rgb(RgbColor(color.into()))), - None => None, - } + serato_tags.track_color().and_then(|color| { + color + .into_displayed_track_color() + .map(Into::into) + .map(RgbColor) + .map(Color::Rgb) + }) } -- GitLab From d3ab2cf0a2ac5763a923de849e7d0734a885bf6a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 12 Feb 2021 00:29:29 +0100 Subject: [PATCH 7/7] media/util/serato: Remove unneeded closure in read_track_color() function --- media/src/util/serato.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/media/src/util/serato.rs b/media/src/util/serato.rs index 92a973e5..f828bec9 100644 --- a/media/src/util/serato.rs +++ b/media/src/util/serato.rs @@ -23,7 +23,7 @@ use aoide_core::{ CanonicalizeInto as _, }, }; -use triseratops::tag::TagContainer; +use triseratops::tag::{color::Color as SeratoColor, TagContainer}; /// Return a canonical vector of cues found in the tag container. pub fn read_cues(serato_tags: &TagContainer) -> Result> { @@ -69,11 +69,10 @@ pub fn read_cues(serato_tags: &TagContainer) -> Result> { } pub fn read_track_color(serato_tags: &TagContainer) -> Option { - serato_tags.track_color().and_then(|color| { - color - .into_displayed_track_color() - .map(Into::into) - .map(RgbColor) - .map(Color::Rgb) - }) + serato_tags + .track_color() + .and_then(SeratoColor::into_displayed_track_color) + .map(Into::into) + .map(RgbColor) + .map(Color::Rgb) } -- GitLab