dev (#1)
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details

Co-authored-by: AnActualEmerald <emerald_actual@proton.me>
Reviewed-on: https://gitea.greenboi.me/Emerald/cathode/pulls/1
This commit is contained in:
Emerald 2022-09-17 17:59:44 +00:00
parent 29ad130193
commit f109d5082c
47 changed files with 1107 additions and 697 deletions

View File

@ -1,12 +1,20 @@
pipeline:
setup:
image: ivangabriele/tauri:bullseye-node18
when:
event: [push, pull_request, tag]
branch: main
commands:
- npm i -D @tauri-apps/cli
build:
image: ivangabriele/tauri:bullseye-node18
when:
event: [push, pull_request, tag]
branch: main
commands:
- apt install libasound2-dev
- npm ci
- npm run tauri build -b
- npm run tauri build

View File

@ -1,4 +1,4 @@
# Cathode [![status-badge](https://ci.greenboi.me/api/badges/Emerald/cathode/status.svg)](https://ci.greenboi.me/Emerald/cathode)
A small app for PNG tubing. Think Veadotub-mini but completely FOSS.
A small app for PNG tubing. Think Veadotube-mini but completely FOSS.
Built with Tauri and Svelte.

4
dist/index.html vendored
View File

@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Svelte + TS</title>
<script type="module" crossorigin src="/assets/index.f473b4a5.js"></script>
<link rel="stylesheet" href="/assets/index.80ecf419.css">
<script type="module" crossorigin src="/assets/index.4fc3067b.js"></script>
<link rel="stylesheet" href="/assets/index.425121d3.css">
</head>
<body>

View File

@ -1,12 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Svelte + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>

648
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"name": "cathode-tube",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 848 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 KiB

50
public/mic.svg Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 330 330" style="enable-background:new 0 0 330 330;" xml:space="preserve">
<g id="XMLID_894_">
<g id="XMLID_895_">
<path id="XMLID_896_" d="M164.998,210c35.888,0,65.085-29.195,65.085-65.12l-0.204-80c0-35.775-29.105-64.88-64.881-64.88
c-35.773,0-64.877,29.105-64.877,64.842l-0.203,80.076C99.918,180.805,129.112,210,164.998,210z M130.121,64.88
c0-19.233,15.646-34.88,34.877-34.88c19.233,0,34.881,15.647,34.881,34.919l0.204,80c0,19.344-15.739,35.081-35.085,35.081
c-19.343,0-35.08-15.737-35.08-35.044L130.121,64.88z"/>
</g>
<g id="XMLID_899_">
<path id="XMLID_900_" d="M280.084,154.96c0-8.284-6.716-15-15-15c-8.284,0-15,6.716-15,15c0,46.732-37.878,84.774-84.546,85.068
c-0.181-0.006-0.357-0.027-0.54-0.027c-0.183,0-0.359,0.021-0.541,0.027c-46.665-0.293-84.541-38.335-84.541-85.068
c0-8.284-6.716-15-15-15s-15,6.716-15,15c0,58.373,43.688,106.731,100.082,114.104V300H117c-8.284,0-15,6.716-15,15
s6.716,15,15,15h96.001c8.284,0,15-6.716,15-15s-6.716-15-15-15h-33.003v-30.936C236.395,261.69,280.084,213.332,280.084,154.96z"
/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

1
public/mouth.svg Normal file
View File

@ -0,0 +1 @@
<svg width="64px" height="64px" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--emojione-monotone" preserveAspectRatio="xMidYMid meet"><path d="M32 2C15.432 2 2 15.432 2 32s13.432 30 30 30s30-13.432 30-30S48.568 2 32 2zm0 57.5C16.836 59.5 4.5 47.164 4.5 32S16.836 4.5 32 4.5S59.5 16.836 59.5 32S47.164 59.5 32 59.5z" fill="currentColor"></path><circle cx="32" cy="45.139" r="7" fill="currentColor"></circle><circle cx="20.248" cy="25.045" r="4.5" fill="currentColor"></circle><circle cx="42.75" cy="25.045" r="4.5" fill="currentColor"></circle></svg>

After

Width:  |  Height:  |  Size: 654 B

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,6 +0,0 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -11,6 +11,12 @@ pub(crate) struct Archive {
}
impl Archive {
pub(crate) fn open(data: &[u8]) -> Self {
Self {
buffer: data.to_vec(),
}
}
pub(crate) fn new() -> Self {
let mut buffer = vec![];
ZipWriter::new(Cursor::new(&mut buffer));
@ -23,9 +29,11 @@ impl Archive {
pub(crate) fn add_file(&mut self, file_name: &str, data: &[u8]) -> Result<()> {
let mut zip = ZipWriter::new_append(Cursor::new(&mut self.buffer))?;
let options = FileOptions::default().compression_method(zip::CompressionMethod::Bzip2);
let options = FileOptions::default()
.compression_method(zip::CompressionMethod::Bzip2)
.compression_level(Some(9));
zip.start_file(file_name, options)?;
zip.write(data)?;
zip.write_all(data)?;
zip.finish()?;
Ok(())

View File

@ -1,5 +1,9 @@
use anyhow::Result;
use std::{collections::HashMap, path::Path};
use std::{
collections::{hash_map::Keys, HashMap},
fs,
path::Path,
};
use crate::archive::Archive;
@ -11,6 +15,14 @@ pub struct Ray {
}
impl Ray {
pub fn get_meta_keys(&self) -> Keys<String, String> {
self.meta.keys()
}
pub fn get_meta_value(&self, key: &str) -> Option<&String> {
self.meta.get(key)
}
pub fn get_frame(&self, index: usize) -> Option<&Vec<u8>> {
self.frames.get(index)
}
@ -24,6 +36,10 @@ impl Ray {
}
}
pub fn add_meta(&mut self, key: String, value: String) -> bool {
self.meta.insert(key, value).is_none()
}
pub fn save(&self, path: &Path) -> Result<()> {
let mut archive = Archive::new();
for (i, f) in self.frames.iter().enumerate() {
@ -38,6 +54,27 @@ impl Ray {
let meta = serde_json::to_string(&self.meta)?;
archive.add_file("meta.json", meta.as_bytes())?;
fs::write(path, archive.buffer())?;
Ok(())
}
pub fn load(path: impl AsRef<Path>) -> Result<Self> {
let mut ray = Self::default();
let data = fs::read(path.as_ref())?;
let archive = Archive::open(&data);
for i in 0..4 {
if let Ok(buf) = archive.get_file(&i.to_string()) {
ray.set_frame(i as usize, buf);
}
}
if let Ok(buf) = archive.get_file("meta.json") {
let meta: HashMap<String, String> = serde_json::from_slice(&buf)?;
ray.meta = meta;
}
Ok(ray)
}
}

530
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package]
name = "cathode-tube"
version = "0.0.0"
version = "0.0.1"
description = "A Tauri App"
authors = ["AnActualEmerald"]
license = "GPL-3.0-or-later"
@ -9,13 +9,19 @@ edition = "2021"
[workspace]
[profile.release]
strip = true
opt-level = "s"
lto = true
codegen-units = 1
[build-dependencies]
tauri-build = { version = "1.0.0", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0", features = ["dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "macos-private-api", "window-minimize", "window-set-max-size", "window-set-min-size", "window-unminimize"] }
tauri = { version = "1.0.0", features = ["cli", "dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "macos-private-api", "window-minimize", "window-set-max-size", "window-set-min-size", "window-unminimize"] }
cpal = { version = "0.14.0", features = ["jack"] }
ray_format = {path = "../ray_format", version = "~0.1.0"}
anyhow = "1.0.63"

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/cathode">
<comment>Cathode RAY file</comment>
<sub-class-of type="application/zip" />
<icon name="application-cathode" />
<acronym>RAY</acronym>
<glob pattern="*.ray"/>
</mime-type>
</mime-info>

View File

@ -0,0 +1,10 @@
[Desktop Entry]
Type=Application
Icon=cathode-tube
Name=Cathode
Exec=cathode-tube %U
Terminal=false
Hidden=false
Categories=Graphics; Video
Comment=Small app for PNG-tubing
MimeType=application/cathode

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1,5 +1,6 @@
use std::sync::Arc;
use std::sync::Mutex;
use std::thread::sleep;
use std::time::Duration;
use anyhow::anyhow;
@ -8,12 +9,12 @@ use cpal::traits::StreamTrait;
use cpal::traits::{DeviceTrait, HostTrait};
use cpal::Device;
use cpal::InputCallbackInfo;
// use cpal::OutputCallbackInfo;
use log::debug;
use tauri::Window;
pub async fn monitor(window: Window, threshold: Arc<Mutex<f32>>, level: Arc<Mutex<f32>>) {
let device = initialize().expect("Unable to init audio");
println!("Using device {}", device.name().unwrap());
debug!("Using device {}", device.name().unwrap());
let config = device.default_input_config().unwrap();
let stream = device
.build_input_stream(
@ -38,11 +39,12 @@ pub async fn monitor(window: Window, threshold: Arc<Mutex<f32>>, level: Arc<Mute
)
.unwrap();
println!("Start stream");
stream.play().expect("Error creating input stream");
// The stream will end if it goes out of scope, so just dwell here
loop {}
loop {
sleep(Duration::from_secs(60));
}
}
fn initialize() -> Result<Device> {

View File

@ -1,14 +1,29 @@
use std::collections::HashMap;
use std::io::Cursor;
use std::path::Path;
use base64_url as base64;
use image::ImageFormat;
use log::trace;
use log::{debug, trace};
use ray_format::Ray;
use serde::{Deserialize, Serialize};
use tauri::api::dialog::blocking::FileDialogBuilder;
use tauri::api::path::home_dir;
const OBJ_URL: &'static str = "data:image/png;base64,";
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct WebRay {
frames: [String; 4],
meta: HashMap<String, String>,
}
#[tauri::command]
pub(crate) async fn open_image() -> Option<String> {
let path = FileDialogBuilder::new()
.add_filter("Images", &["png", "jpg"])
.set_directory(home_dir()?)
.set_title("Select an image")
.pick_file()?;
if let Ok(b) = image::open(path) {
let mut buf = Cursor::new(vec![]);
@ -16,8 +31,74 @@ pub(crate) async fn open_image() -> Option<String> {
let encoded = base64::encode(buf.get_ref());
trace!("Encoded: {:?}", encoded);
Some(format!("data:image/png;base64,{}", encoded))
Some(format!("{}{}", OBJ_URL, encoded))
} else {
None
}
}
#[tauri::command]
pub(crate) async fn open_ray() -> Option<WebRay> {
let path = FileDialogBuilder::new()
.add_filter("Rays", &["ray"])
.set_directory(home_dir()?)
.pick_file()?;
load_ray(path).await
}
pub(crate) async fn load_ray(path: impl AsRef<Path>) -> Option<WebRay> {
let ray = Ray::load(path).ok()?;
let mut frames = [String::new(), String::new(), String::new(), String::new()];
let mut meta = HashMap::new();
for i in 0..4 {
debug!("Trying frame {}", i);
if let Some(f) = ray.get_frame(i as usize) {
debug!("Got frame {}", i);
if f.is_empty() {
debug!("Frame {} was empty", i);
continue;
}
let encoded = base64::encode(&f);
frames[i as usize] = format!("{}{}", OBJ_URL, encoded);
}
}
for k in ray.get_meta_keys() {
if let Some(v) = ray.get_meta_value(&k) {
meta.insert(k.clone(), v.clone());
}
}
Some(WebRay { frames, meta })
}
#[tauri::command]
pub(crate) async fn save_ray(ray: WebRay) -> Result<(), String> {
if let Some(path) = FileDialogBuilder::new()
.add_filter("Rays", &["ray"])
.set_directory(home_dir().unwrap())
.set_title("Save Ray")
.set_file_name("new.ray")
.save_file()
{
let mut res = Ray::default();
for (i, f) in ray.frames.iter().enumerate() {
let stripped = f.strip_prefix(OBJ_URL).unwrap_or(f);
let decoded = base64::decode(stripped).unwrap();
res.set_frame(i as usize, decoded);
}
for (k, v) in ray.meta {
res.add_meta(k, v);
}
res.save(&path)
.map_err(|e| format!("Failed to save ray file: {}", e))
} else {
Ok(())
}
}

View File

@ -4,12 +4,14 @@
)]
use std::{
path::Path,
sync::{Arc, Mutex},
time::Duration,
};
use audio::monitor;
use log::{trace, warn};
use serde_json::Value;
use tauri::{Manager, State};
mod audio;
@ -47,18 +49,40 @@ fn main() {
}
});
if let Ok(matches) = app.get_cli_matches() {
if let Some(arg) = matches.args.get("file") {
if let Value::String(path) = arg.value.clone() {
let window = app.get_window("main").unwrap();
let path = Path::new(&path).canonicalize().unwrap();
tauri::async_runtime::spawn(async move {
if let Some(ray) = fs::load_ray(Path::new(&path)).await {
window.emit("load-ray", ray).unwrap();
}
});
}
}
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
log,
set_mic_threshold,
get_mic_threshold,
get_audio_level,
fs::open_image,
fs::save_ray,
fs::open_ray,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
fn log(msg: String) {
println!("{}", msg);
}
#[tauri::command]
fn set_mic_threshold(threshold: f32, current: State<'_, MicThreshold>) {
*current.0.lock().unwrap() = threshold;

View File

@ -7,9 +7,17 @@
},
"package": {
"productName": "cathode-tube",
"version": "0.0.0"
"version": "0.0.1"
},
"tauri": {
"cli": {
"description": "A small app for PNG-tubing",
"args": [{
"name": "file",
"index": 1,
"takesValue": true
}]
},
"macOSPrivateApi": true,
"allowlist": {
"dialog": {
@ -34,6 +42,11 @@
"category": "DeveloperTool",
"copyright": "",
"deb": {
"files" : {
"/usr/share/applications/cathode-tube.desktop": "cathode-tube.desktop",
"/usr/share/mime/packages/application-cathode.xml": "application-cathode.xml",
"/usr/share/icons/hicolor/256x256/mimetypes/aplication-cathode.png": "icons/application-cathode-256.png"
},
"depends": []
},
"externalBin": [],

View File

@ -60,12 +60,16 @@
align-content: center;
justify-content: center;
border-radius: 10px;
border: 2px solid black;
background-color: $bg;
width: 20vh;
height: 20vh;
width: 15vh;
height: 15vh;
user-select: none;
cursor: pointer;
}
.box {
user-select: none;
gap: 10px;
display: flex;
.context {
@ -75,5 +79,6 @@
img {
width: 75%;
user-select: none;
}
</style>

View File

@ -1,63 +1,125 @@
<script lang="ts">
import { draggable } from "@neodrag/svelte";
import { onMount } from "svelte";
import { tweened } from "svelte/motion";
import { quintOut } from "svelte/easing";
import { sineIn, sineOut } from "svelte/easing";
import { invoke } from "@tauri-apps/api";
export let progress = 0;
export let withSetpoint = false;
export let setpoint = 0;
export let onSetpointChange = (e: number) => {};
export let onSetpointChange = (_: number) => {};
let bar;
const tweenedProgress = tweened(0, { duration: 100, easing: quintOut });
let bar: HTMLDivElement;
let point: HTMLDivElement;
let pos = { x: 0, y: 0 };
const tweenedProgress = tweened(0, { duration: 40, easing: sineOut });
$: $tweenedProgress = progress;
onMount(async () => {
let rect = bar.getBoundingClientRect();
let prect = point.getBoundingClientRect();
pos.y = -(setpoint / 100) * rect.height + prect.height;
});
$: if (bar) {
let pxProgress = (progress / 100) * bar.getBoundingClientRect().height;
if (pxProgress > $tweenedProgress) {
tweenedProgress
.set(pxProgress, {
duration: 20,
easing: sineOut,
})
.then();
}
$tweenedProgress = pxProgress;
}
</script>
<div bind:this={bar} class="bar-container">
{#if withSetpoint}
<div
class="setpoint"
style="bottom: {setpoint}%"
use:draggable={{
axis: "y",
bounds: "parent",
onDragEnd: (e) => {
let rect = bar.getBoundingClientRect();
let y = e.domRect.y / (rect.height + rect.y);
onSetpointChange(1.0 - y);
},
}}
/>
{/if}
<div class="bar" style="height: {$tweenedProgress}%;" />
<svelte:window
on:resize={async () => {
await invoke("log", {
msg: `Resized`,
});
pos = { x: 0, y: 0 };
let rect = bar.getBoundingClientRect();
let prect = point.getBoundingClientRect();
pos.y = -(setpoint / 100) * rect.height + prect.height;
}}
/>
<div class="box">
<div bind:this={bar} class="bar-container">
{#if withSetpoint}
<div
bind:this={point}
class="setpoint"
use:draggable={{
onDragStart: () => (pos = undefined),
handle: ".handle",
position: pos,
axis: "y",
bounds: "parent",
onDragEnd: (e) => {
let rect = bar.getBoundingClientRect();
let y = (e.domRect.y - rect.y + e.domRect.height / 2) / rect.height;
onSetpointChange(1.0 - y);
},
}}
>
<div class="handle" />
</div>
{/if}
<div class="bar" style="height: {$tweenedProgress}px;" />
</div>
<slot class="icon" />
</div>
<style lang="scss">
.bar-container {
.setpoint {
position: absolute;
background-color: black;
width: 120%;
height: 2vh;
left: -10%;
.box {
display: flex;
flex-direction: column;
align-items: center;
gap: 1vh;
:global(img) {
width: var(--bar-width, 5vh);
}
}
.setpoint {
position: absolute;
background-color: black;
width: var(--bar-width, 5vh);
height: 0.5vh;
.handle {
position: absolute;
border-top: 2vh solid transparent;
border-bottom: 2vh solid transparent;
border-left: 2vh solid var(--handle-color, forestgreen);
left: -2.2vh;
top: 50%;
transform: translateY(-50%);
}
}
.bar-container {
border-radius: var(--bar-radius, 0px);
display: flex;
flex-direction: column;
justify-content: flex-end;
background-color: white;
border: 2px solid black;
height: 80vh;
width: 10vh;
width: var(--bar-width, 5vh);
}
.bar {
border-radius: inherit;
user-select: none;
width: 100%;
border: 0;
margin: 0;
background-color: var(--bar-color, blue);
transition: background-color 0.1s;
}
</style>

View File

@ -6,16 +6,14 @@
let src = "";
export let buf = 0;
export let open = false;
export let threshold = 50;
let closed = false;
let blink = false;
let inAnim = "jump-in";
let outAnim = "none";
$: {
if (buf > 50) {
open = true;
closed = false;
} else {
if (buf < threshold) {
open = false;
closed = true;
}
@ -38,10 +36,12 @@
onMount(async () => {
await appWindow.listen("mouth-open", () => {
buf = 100;
open = true;
closed = false;
});
await appWindow.listen("mouth-close", () => {
buf = buf - 10;
buf = buf - 5;
buf = buf < 0 ? 0 : buf;
});

View File

@ -1,39 +1,123 @@
<script lang="ts" context="module">
import { writable } from "svelte/store";
import { writable, type Writable } from "svelte/store";
const transparent = writable(false);
let threshold = writable(0);
let level = writable(0);
const threshold: Writable<number> = writable(0.5);
const level = writable(0);
type WebRay = {
frames: Array<string>;
meta: {
threshold: string | undefined;
closeThreshold: string | undefined;
};
};
</script>
<script lang="ts">
import { appWindow, PhysicalSize } from "@tauri-apps/api/window";
import { onMount, beforeUpdate, afterUpdate } from "svelte";
import { onMount, onDestroy } from "svelte";
import { fly } from "svelte/transition";
import FramePreview from "../components/FramePreview.svelte";
import Tuber from "../components/tube.svelte";
import { invoke } from "@tauri-apps/api/tauri";
import Bar from "../components/bar.svelte";
import { tick } from "svelte";
import { frames } from "../store";
import { quintInOut } from "svelte/easing";
let monitorTimer: NodeJS.Timer;
let active = false;
let activation = 0;
let closeThreshold = 75;
$: {
invoke("set_mic_threshold", { threshold: $threshold as number })
.then()
.catch(async (e) => {
await invoke("log", { msg: `Error setting mic threshold: ${e}` });
});
}
const openRay = (ray: WebRay) => {
for (let i = 0; i < 4; i++) {
$frames[i] = ray.frames[i];
}
if (ray.meta.threshold) {
$threshold = parseFloat(ray.meta.threshold);
}
if (ray.meta.closeThreshold) {
closeThreshold = parseFloat(ray.meta.closeThreshold);
}
};
onMount(async () => {
await appWindow.setMinSize(new PhysicalSize(720, 600));
await appWindow.onFocusChanged(({ payload: focused }) => {
$transparent = !focused;
});
setInterval(async () => ($level = await invoke("get_audio_level")), 10);
});
beforeUpdate(async () => {
await appWindow.listen("load-ray", (e) => {
openRay(e.payload as WebRay);
});
monitorTimer = setInterval(async () => {
if (!$transparent) {
$level = await invoke("get_audio_level");
await tick();
}
}, 40);
$threshold = await invoke("get_mic_threshold");
});
onDestroy(() => {
if (monitorTimer) {
clearInterval(monitorTimer);
monitorTimer = undefined;
}
});
const saveRay = async () => {
let fr = new Array<string>(4);
for (let i = 0; i < 4; i++) {
$frames[i] ? (fr[i] = $frames[i]) : (fr[i] = "");
}
fr.map((e) => (e ? e : ""));
const ray = {
frames: [fr[0], fr[1], fr[2], fr[3]],
meta: {
threshold: $threshold.toString(),
closeThreshold: closeThreshold.toString(),
},
};
// await invoke("log", { msg: `Saving ray: ${JSON.stringify(ray)}` });
invoke("save_ray", { ray })
.then()
.catch((e) => invoke("log", { msg: e }).then());
};
const loadRay = async () => {
const ray: WebRay = await invoke("open_ray");
openRay(ray);
};
</script>
<div class="container" class:transparent={$transparent}>
<Tuber />
<Tuber
bind:open={active}
bind:buf={activation}
bind:threshold={closeThreshold}
/>
{#if !$transparent}
<div
transition:fly={{ duration: 200, x: -200, opacity: 100 }}
transition:fly={{
duration: 200,
x: -200,
opacity: 100,
easing: quintInOut,
}}
class="frames"
>
{#each [0, 1, 2, 3] as i}
@ -41,17 +125,48 @@
{/each}
</div>
<div transition:fly={{ duration: 200, x: 200, opacity: 100 }} class="audio">
<Bar
progress={$level * 100}
setpoint={$threshold * 100}
withSetpoint
onSetpointChange={async (e) => {
// $threshold = e;
await invoke("set_mic_threshold", { threshold: e });
}}
--bar-color={active ? "green" : "blue"}
/>
<div
transition:fly={{
duration: 200,
x: 200,
opacity: 100,
easing: quintInOut,
}}
class="audio"
>
{#key $threshold}
<Bar
progress={$level * 100}
setpoint={$threshold * 100}
withSetpoint
onSetpointChange={async (e) => {
$threshold = e;
}}
--bar-color={active ? "lightgreen" : "blue"}
><img src="mic.svg" alt="microphone" /></Bar
>
{/key}
{#key closeThreshold}
<Bar
withSetpoint
progress={activation}
setpoint={closeThreshold}
onSetpointChange={(y) => (closeThreshold = y * 100)}
><img src="mouth.svg" alt="mouth" /></Bar
>
{/key}
</div>
<div
transition:fly={{
duration: 200,
y: -100,
opacity: 100,
easing: quintInOut,
}}
class="buttons"
>
<div on:click={saveRay}>Save</div>
<div on:click={loadRay}>Load</div>
</div>
{/if}
</div>
@ -59,6 +174,29 @@
<svelte:body on:contextmenu|preventDefault />
<style lang="scss">
.buttons {
position: absolute;
top: 2vh;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
justify-items: center;
gap: 5vh;
div {
color: white;
padding: 10px;
border-radius: 5px;
background-color: rgba(0.5, 0.5, 0.5, 0.5);
border: solid black 2px;
user-select: none;
cursor: pointer;
&:hover {
background-color: rgba(0.9, 0.9, 0.9, 0.9);
}
}
}
.frames {
align-items: left;
position: absolute;
@ -73,10 +211,10 @@
.audio {
position: absolute;
display: flex;
gap: 10px;
gap: 2.5vh;
bottom: 5vh;
top: 5vh;
right: 30px;
right: 20px;
}
@keyframes fade-out {