Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/new-web-ui' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mjleehh committed Dec 16, 2024
2 parents 107497f + e827d5a commit 972376d
Show file tree
Hide file tree
Showing 60 changed files with 1,963 additions and 137 deletions.
26 changes: 18 additions & 8 deletions apps/desktop/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,44 @@
#include <tbd/sound_manager.hpp>
#include <tbd/sound_processor/allocator.hpp>
#include <tbd/api/rest_api.hpp>
#include <tbd/favorites.hpp>


namespace po = boost::program_options;

int main(int argc, char** argv) {
std::string input_file;
uint16_t port;
uint32_t device;
std::string output_file;
bool start_paused;

po::options_description desc(std::string(argv[0]) + " options");
po::variables_map vm;
desc.add_options()
("help,h", "this help message")
// ("srom,s", po::value<string>(&sromFile)->default_value("../../sample_rom/sample-rom.tbd"),
// "file for sample rom emulation, default ../../sample_rom/sample-rom.tbd")
// ("list,l", po::bool_switch(&bListSoundCards)->default_value(false), "list sound cards")
// ("device,d", po::value<int>(&iDeviceNum)->default_value(0), "sound card device id, default 0")
// ("output,o", po::bool_switch(&bOutputOnly)->default_value(false),
// "use output only (if no duplex device available)")
("port,p", po::value<uint16_t>(&port)->default_value(2024), "port for REST api"),
("wav,w", po::value<std::string>(&input_file),
"read audio in from wav file (arg), must be 2 channel stereo float32 data, will be cycled through indefinitely");
("help,h", "this help message")
("device,d", po::value(&device)->default_value(-1), "sound card device id, default 0")
("port,p", po::value<uint16_t>(&port)->default_value(2024), "port for REST api")
("wav,w", po::value(&input_file))
("output,o", po::value(&output_file),
"read audio in from wav file (arg), must be 2 channel stereo float32 data, will be cycled through indefinitely")
("paused", po::bool_switch(&start_paused)->default_value(false), "start app in paused mode");

store(po::parse_command_line(argc, argv, desc), vm);
notify(vm);

tbd::Favorites::init();

// reserve large block of memory before anything else happens
CTAG::SP::ctagSPAllocator::AllocateInternalBuffer(114688); // TBDings has highest needs of 113944 bytes, take 112k=114688 bytes as default

tbd::audio::SoundProcessorManager::begin(tbd::audio::AudioParams(input_file));
tbd::audio::SoundProcessorManager::begin(tbd::audio::AudioParams(input_file, output_file, device));
if (start_paused) {
tbd::audio::SoundProcessorManager::DisablePluginProcessing();
}

tbd::api::RestApiParams params = {.port = port};
tbd::api::RestApi::begin(params);
Expand Down
24 changes: 24 additions & 0 deletions astro-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build output
dist/

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/
4 changes: 4 additions & 0 deletions astro-frontend/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions astro-frontend/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
54 changes: 54 additions & 0 deletions astro-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Astro Starter Kit: Basics

```sh
npm create astro@latest -- --template basics
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics)
[![Open in GitHub Codespaces](/~https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
![just-the-basics](/~https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554)

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
│ └── favicon.svg
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
└── package.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

Any static assets, like images, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
13 changes: 13 additions & 0 deletions astro-frontend/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import { defineConfig } from "astro/config";

import tailwind from "@astrojs/tailwind";

import preact from "@astrojs/preact";

// https://astro.build/config
export default defineConfig({
output: process.env.NODE_ENV === "production" ? "static" : "server",
outDir: "../spiffs_image/www",
integrations: [tailwind(), preact({ compat: true })],
});
Binary file added astro-frontend/bun.lockb
Binary file not shown.
12 changes: 12 additions & 0 deletions astro-frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import eslintPluginAstro from "eslint-plugin-astro";
export default [
// add more generic rule sets here, such as:
// js.configs.recommended,
...eslintPluginAstro.configs.recommended,
{
rules: {
// override/add rules settings here, such as:
// "astro/no-set-html-directive": "error"
},
},
];
36 changes: 36 additions & 0 deletions astro-frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "",
"version": "0.0.1",
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/preact": "^3.5.3",
"@astrojs/tailwind": "^5.1.2",
"@nanostores/persistent": "^0.10.2",
"@nanostores/preact": "^0.5.2",
"astro": "^4.16.10",
"daisyui": "^4.12.14",
"nanostores": "^0.11.3",
"preact": "^10.24.3",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
},
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro",
"lint": "eslint .",
"format": "prettier . --write"
},
"type": "module",
"devDependencies": {
"@tailwindcss/typography": "^0.5.15",
"@types/node": "^22.9.0",
"@typescript-eslint/parser": "^8.13.0",
"eslint": "^9.14.0",
"eslint-plugin-astro": "^1.3.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1"
}
}
12 changes: 12 additions & 0 deletions astro-frontend/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import("prettier").Config} */
export default {
plugins: ["prettier-plugin-astro"],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
},
],
};
Binary file added astro-frontend/public/favicon.ico
Binary file not shown.
82 changes: 82 additions & 0 deletions astro-frontend/src/components/EditFavorite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useStore } from "@nanostores/preact";
import { $favorites, type FavoritePreset } from "../stores/favoritesStore";
import { useEffect, useState } from "preact/hooks";

export interface EditFavoriteProps {
num: number;
favoriteData?: FavoritePreset;
}

export default function EditCurrrentFavorite({
num,
favoriteData,
}: EditFavoriteProps) {
const favorites = useStore($favorites);
const currentFavorite = favoriteData ?? favorites.at(num);
const [name, setName] = useState<string>("");
const [ustring, setUstring] = useState<string>("");

useEffect(() => {
if (currentFavorite) {
setName(currentFavorite.name);
setUstring(currentFavorite.ustring);
}
}, [currentFavorite]);

const handleSave = async () => {
if (!currentFavorite) {
return;
}

const data: FavoritePreset = {
...currentFavorite,
name,
ustring,
};

const response = await fetch(`/api/v1/favorites/store/${num}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});

if (response.ok) {
favorites[num] = data;
$favorites.set(favorites);
}
};

return (
<div>
<label className="form-control w-full max-w-xs">
<div className="label">
<span className="label-text">Name</span>
</div>
<input
type="text"
className="input input-bordered w-full max-w-xs"
value={name}
onChange={(e) => setName(e.currentTarget.value)}
/>
</label>

<label className="form-control w-full max-w-xs">
<div className="label">
<span className="label-text">User String</span>
</div>
<input
type="text"
className="input input-bordered w-full max-w-xs"
value={ustring}
onChange={(e) => setUstring(e.currentTarget.value)}
/>
</label>

<button className="btn" onClick={handleSave}>
Save
</button>
</div>
);
}
47 changes: 47 additions & 0 deletions astro-frontend/src/components/FavoritesButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useStore } from "@nanostores/preact";
import { $currentFavoriteNum } from "../stores/favoritesStore";
import { $activePlugins, type Plugin } from "../stores/pluginsStore";

export default function FavoritesButtons() {
const currentFavorite = useStore($currentFavoriteNum);

const handleRecall = async () => {
const response = await fetch(
`/api/v1/favorites/recall/${currentFavorite}`,
{ method: "POST" },
);

if (!response.ok) {
return;
}

const channelOneFetch = fetch("/api/v1/getActivePlugin/0")
.then((r) => r.json())
.then(({ id }: Pick<Plugin, "id">) => $activePlugins.setKey("0", { id }));
const channelTwoFetch = fetch("/api/v1/getActivePlugin/1")
.then((r) => r.json())
.then(({ id }: Pick<Plugin, "id">) => $activePlugins.setKey("1", { id }));

await Promise.all([channelOneFetch, channelTwoFetch]);
};

return (
<div>
<button className="btn" onClick={handleRecall}>
Recall
</button>
<a role="button" className="btn" href={`/fav/${currentFavorite}/snap`}>
Snap
</a>
<a role="button" className="btn" href={`/fav/${currentFavorite}/edit`}>
Edit
</a>
<button className="btn" onClick={handleRecall}>
Export
</button>
<button className="btn" onClick={handleRecall}>
Import
</button>
</div>
);
}
27 changes: 27 additions & 0 deletions astro-frontend/src/components/FavoritesSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useStore } from "@nanostores/preact";
import { $currentFavoriteNum, $favorites } from "../stores/favoritesStore";

export default function FavoritesSelect() {
const favorites = useStore($favorites);
const currentFavorite = useStore($currentFavoriteNum);

return (
<select
class="select w-full max-w-xs"
value={currentFavorite}
onChange={(event) => {
const newFavorite = Number.parseInt(event.currentTarget.value, 10);

if (!Number.isNaN(newFavorite)) {
$currentFavoriteNum.set(newFavorite);
}
}}
>
{favorites.map((favorite, i) => (
<option value={i}>
{i}: {favorite.name}
</option>
))}
</select>
);
}
Loading

0 comments on commit 972376d

Please sign in to comment.