Skip to content

Commit

Permalink
Merge pull request #1 from amydevs/feature-ts
Browse files Browse the repository at this point in the history
Feature ts
  • Loading branch information
amydevs authored Jul 26, 2024
2 parents fed7621 + 2283d23 commit 064c47f
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 78 deletions.
62 changes: 61 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "altc"
version = "0.1.10"
version = "0.2.1"
edition = "2021"
description = "Convert Live 10, 11, and 12 themes"
readme = "README.md"
Expand Down Expand Up @@ -31,6 +31,7 @@ quick-xml = { version = "0", features = ["serialize"] }
regex = "1"
serde = { version = "1", features = ["derive"] }
wasm-bindgen = "0.2"
tsify = "0.4"
serde_with = "3"
# bin stuff
clap = { version = "4", features = ["derive"] , optional = true }
Expand Down
5 changes: 3 additions & 2 deletions src/bin/schemagen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ fn main() -> core::result::Result<(), String> {
use crate::common::{HexColor, Meter, ValueWrapper};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use tsify::Tsify;

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[serde(rename_all = "PascalCase")]
pub struct #theme_class_token_stream {
#( #fields ),*
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Tsify)]
pub struct Ableton {
#[serde(rename = "@MajorVersion")]
pub major_version: Option<String>,
Expand Down
23 changes: 19 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@ use serde::{
Deserialize, Deserializer, Serialize, Serializer,
};
use serde_with::skip_serializing_none;
use tsify::Tsify;
use wasm_bindgen::prelude::*;



#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct ValueWrapper<T> {
#[serde(rename = "@Value")]
pub value: T,
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "ValueWrapper")]
pub type ValueWrapperJsType;
}
impl<T> Tsify for ValueWrapper<T> {
type JsType = ValueWrapperJsType;
const DECL: &'static str = "export interface ValueWrapper<T> {\n \"@Value\": T;\n}";
}
#[wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = "export interface ValueWrapper<T> {\n \"@Value\": T;\n}";

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Tsify)]
pub struct Color {
pub r: u8,
pub g: u8,
Expand All @@ -30,7 +45,7 @@ impl Default for Color {
}

#[skip_serializing_none]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Tsify)]
#[serde(default, rename_all = "PascalCase")]
pub struct RGBAColor {
#[serde(deserialize_with = "deserialize_coerce_u8")]
Expand Down Expand Up @@ -89,7 +104,7 @@ where
}

#[skip_serializing_none]
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Tsify)]
pub struct HexColor {
pub value: Color,
}
Expand Down Expand Up @@ -182,7 +197,7 @@ impl Into<RGBAColor> for HexColor {
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[serde(rename_all = "PascalCase")]
pub struct Meter {
pub only_minimum_to_maximum: Option<ValueWrapper<bool>>,
Expand Down
50 changes: 26 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ pub mod live10;
pub mod live11;
pub mod live12;
pub mod util;
#[cfg(target_arch = "wasm32")]
pub mod wasm;

impl Into<live10::Ableton> for live11::Ableton {
fn into(self) -> live10::Ableton {
live10::Ableton {
impl Into<live10::Ableton10> for live11::Ableton11 {
fn into(self) -> live10::Ableton10 {
live10::Ableton10 {
major_version: Some("5".to_owned()),
minor_version: Some("10.0_373".to_owned()),
schema_change_count: Some("1".to_owned()),
Expand All @@ -19,9 +21,9 @@ impl Into<live10::Ableton> for live11::Ableton {
}
}

impl Into<live10::SkinManager> for live11::Theme {
fn into(self) -> live10::SkinManager {
live10::SkinManager {
impl Into<live10::SkinManager10> for live11::Theme11 {
fn into(self) -> live10::SkinManager10 {
live10::SkinManager10 {
control_foreground: self.control_foreground.and_then(|v| Some(v.into())),
text_disabled: self.text_disabled.and_then(|v| Some(v.into())),
control_disabled: self.control_disabled.and_then(|v| Some(v.into())),
Expand Down Expand Up @@ -290,9 +292,9 @@ impl Into<live10::SkinManager> for live11::Theme {
}
}

impl Into<live11::Ableton> for live10::Ableton {
fn into(self) -> live11::Ableton {
live11::Ableton {
impl Into<live11::Ableton11> for live10::Ableton10 {
fn into(self) -> live11::Ableton11 {
live11::Ableton11 {
major_version: Some("5".to_owned()),
minor_version: Some("11.0_432".to_owned()),
schema_change_count: Some("3".to_owned()),
Expand All @@ -303,9 +305,9 @@ impl Into<live11::Ableton> for live10::Ableton {
}
}

impl Into<live11::Theme> for live10::SkinManager {
fn into(self) -> live11::Theme {
live11::Theme {
impl Into<live11::Theme11> for live10::SkinManager10 {
fn into(self) -> live11::Theme11 {
live11::Theme11 {
control_foreground: self.control_foreground.and_then(|v| Some(v.into())),
text_disabled: self.text_disabled.and_then(|v| Some(v.into())),
control_disabled: self.control_disabled.and_then(|v| Some(v.into())),
Expand Down Expand Up @@ -627,9 +629,9 @@ impl Into<live11::Theme> for live10::SkinManager {
}
}

impl Into<live11::Ableton> for live12::Ableton {
fn into(self) -> live11::Ableton {
live11::Ableton {
impl Into<live11::Ableton11> for live12::Ableton12 {
fn into(self) -> live11::Ableton11 {
live11::Ableton11 {
major_version: Some("5".to_owned()),
minor_version: Some("11.0_432".to_owned()),
schema_change_count: Some("3".to_owned()),
Expand All @@ -640,9 +642,9 @@ impl Into<live11::Ableton> for live12::Ableton {
}
}

impl Into<live11::Theme> for live12::Theme {
fn into(self) -> live11::Theme {
live11::Theme {
impl Into<live11::Theme11> for live12::Theme12 {
fn into(self) -> live11::Theme11 {
live11::Theme11 {
control_foreground: self.control_foreground,
text_disabled: self.text_disabled,
control_disabled: self.control_disabled,
Expand Down Expand Up @@ -866,9 +868,9 @@ impl Into<live11::Theme> for live12::Theme {
}
}

impl Into<live12::Ableton> for live11::Ableton {
fn into(self) -> live12::Ableton {
live12::Ableton {
impl Into<live12::Ableton12> for live11::Ableton11 {
fn into(self) -> live12::Ableton12 {
live12::Ableton12 {
major_version: Some("5".to_owned()),
minor_version: Some("12.0_12047".to_owned()),
schema_change_count: Some("2".to_owned()),
Expand All @@ -879,9 +881,9 @@ impl Into<live12::Ableton> for live11::Ableton {
}
}

impl Into<live12::Theme> for live11::Theme {
fn into(self) -> live12::Theme {
live12::Theme {
impl Into<live12::Theme12> for live11::Theme11 {
fn into(self) -> live12::Theme12 {
live12::Theme12 {
control_foreground: self.control_foreground,
text_disabled: self.text_disabled,
control_disabled: self.control_disabled,
Expand Down
26 changes: 20 additions & 6 deletions src/live10.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::common::{RGBAColor, ValueWrapper};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use tsify::Tsify;
use wasm_bindgen::prelude::*;

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[serde(rename_all = "PascalCase")]
pub struct SkinManager {
pub struct SkinManager10 {
pub control_foreground: Option<RGBAColor>,
pub text_disabled: Option<RGBAColor>,
pub control_disabled: Option<RGBAColor>,
Expand Down Expand Up @@ -190,7 +192,7 @@ pub struct SkinManager {

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
pub struct Ableton {
pub struct Ableton10 {
#[serde(rename = "@MajorVersion")]
pub major_version: Option<String>,
#[serde(rename = "@MinorVersion")]
Expand All @@ -202,17 +204,29 @@ pub struct Ableton {
#[serde(rename = "@Revision")]
pub revision: Option<String>,
#[serde(rename = "SkinManager")]
pub skin_manager: Option<SkinManager>,
pub skin_manager: Option<SkinManager10>,
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "Ableton10")]
pub type AbletonJsType;
}
impl Tsify for Ableton10 {
type JsType = AbletonJsType;
const DECL: &'static str = "export interface Ableton10 {\n \"@MajorVersion?\": string;\n \"@MinorVersion?\": string;\n \"@SchemaChangeCount?\": string;\n \"@Creator?\": string;\n \"@Revision?\": string;\n SkinManager?: SkinManager10;\n}";
}
#[wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &'static str = "export interface Ableton10 {\n \"@MajorVersion?\": string;\n \"@MinorVersion?\": string;\n \"@SchemaChangeCount?\": string;\n \"@Creator?\": string;\n \"@Revision?\": string;\n SkinManager?: SkinManager10;\n}";


#[cfg(test)]
mod tests {
use quick_xml::de::from_str;

use super::Ableton;
use super::Ableton10;
#[test]
fn ableton() {
let ableton: Ableton = from_str(include_str!("../test_themes/blank_10.ask")).unwrap();
let ableton: Ableton10 = from_str(include_str!("../test_themes/blank_10.ask")).unwrap();
assert_eq!(ableton.major_version, Some("5".to_string()));
}
}
Loading

0 comments on commit 064c47f

Please # to comment.