Skip to content

Commit

Permalink
Add Mixery Controller module
Browse files Browse the repository at this point in the history
  • Loading branch information
nahkd123 committed Sep 4, 2023
1 parent 693bfe8 commit adf60f0
Show file tree
Hide file tree
Showing 37 changed files with 1,414 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/controller-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}
28 changes: 28 additions & 0 deletions modules/controller-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions modules/controller-ui/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
46 changes: 46 additions & 0 deletions modules/controller-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# controller-ui

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).

## Project Setup

```sh
pnpm install
```

### Compile and Hot-Reload for Development

```sh
pnpm dev
```

### Type-Check, Compile and Minify for Production

```sh
pnpm build
```

### Lint with [ESLint](https://eslint.org/)

```sh
pnpm lint
```
1 change: 1 addition & 0 deletions modules/controller-ui/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions modules/controller-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/icon.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mixery Controller</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions modules/controller-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@mixery/controller-ui",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "run-p type-check build-only",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"vue": "^3.3.4",
"@mixery/controller": "workspace:*"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.3.2",
"@tsconfig/node18": "^18.2.0",
"@types/node": "^18.17.5",
"@vitejs/plugin-vue": "^4.3.1",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^11.0.3",
"@vue/tsconfig": "^0.4.0",
"eslint": "^8.46.0",
"eslint-plugin-vue": "^9.16.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.0",
"typescript": "~5.1.6",
"vite": "^4.4.9",
"vue-tsc": "^1.8.8"
}
}
9 changes: 9 additions & 0 deletions modules/controller-ui/public/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 139 additions & 0 deletions modules/controller-ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<script setup lang="ts">
import Toolsbar from './components/Toolsbar.vue';
import ToolsbarButton from './components/ToolsbarButton.vue';
import ModulesContainer from './components/modules/ModulesContainer.vue';
import KeyboardModule from './components/modules/KeyboardModule.vue';
import { ref } from 'vue';
import type { Modules } from './components/Modules';
import { LocalControllerConnection } from '@mixery/controller';
import { Controller } from './Controller';
import DrumPadModule from './components/modules/DrumPadModule.vue';
import { ModulesCollision } from './ModulesCollision';
const modules = ref<Modules.Module[]>([]);
modules.value.push({
type: "keyboard",
x: 2, y: 0, width: 5, height: 2,
channel: 0
});
modules.value.push({
type: "drumpad",
x: 0, y: 0, width: 2, height: 2,
channel: 0,
matrix: [4, 4]
});
const connectState = ref<"disconnected" | "connecting" | "connected">("disconnected");
async function connect() {
const { client, host } = LocalControllerConnection.createPair(3000);
Controller.connection = client;
connectState.value = "connecting";
try {
await client.whenConnected;
connectState.value = "connected";
host.listenForMessages(console.log);
} catch (e) {
connectState.value = "disconnected";
}
}
function updateCollision(target: Modules.Module) {
ModulesCollision.process(modules, target);
}
</script>

<template>
<div class="parent">
<Toolsbar>
<ToolsbarButton
class="connect-button"
:class="{
connecting: connectState == 'connecting',
connected: connectState == 'connected'
}"
@click="connect"
>{{ connectState[0].toUpperCase() }}{{ connectState.substring(1) }}</ToolsbarButton>
<ToolsbarButton>Add</ToolsbarButton>
</Toolsbar>
<ModulesContainer class="modules-container">
<template v-for="m in modules">
<KeyboardModule
v-if="m.type == 'keyboard'"
v-model:x="m.x"
v-model:y="m.y"
v-model:width="m.width"
v-model:height="m.height"
v-model:channel="m.channel"
@update-collision="updateCollision(m)"
/>
<DrumPadModule
v-if="m.type == 'drumpad'"
v-model:x="m.x"
v-model:y="m.y"
v-model:width="m.width"
v-model:height="m.height"
v-model:channel="m.channel"
v-model:matrix="m.matrix"
@update-collision="updateCollision(m)"
>
<template v-slot:pad-1-1>
Drum
</template>
</DrumPadModule>
</template>
</ModulesContainer>
</div>
</template>

<style scoped lang="scss">
.parent {
display: flex;
flex-direction: column;
width: 100vw;
height: 100vh;
user-select: none;
overscroll-behavior: none;
.modules-container {
flex: 1 1 auto;
}
.connect-button {
--color-indicator: #ff7f7f;
color: var(--color-indicator);
transition: 0.5s linear color;
&::before {
content: '';
display: inline-block;
width: 10px;
height: 10px;
border-radius: 1000px;
background-color: var(--color-indicator);
margin-right: 8px;
transition: 0.5s linear background-color;
}
&.connecting { --color-indicator: #ffff7f; }
&.connected { --color-indicator: #7fff7f; }
&.connecting::before, &.connected::before {
@keyframes tetherAnimation {
0% {
box-shadow: 0 0 0 0 var(--color-indicator);
}
50% {
box-shadow: 0 0 0 8px transparent;
}
100% {
box-shadow: 0 0 0 8px transparent;
}
}
animation: 2s infinite linear tetherAnimation;
}
}
}
</style>
5 changes: 5 additions & 0 deletions modules/controller-ui/src/Controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { ControllerConnection } from "@mixery/controller";

export namespace Controller {
export let connection: ControllerConnection | undefined;
}
8 changes: 8 additions & 0 deletions modules/controller-ui/src/ModulesCollision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type Ref } from "vue";
import type { Modules } from "./components/Modules";

export namespace ModulesCollision {
export function process(ref: Ref<Modules.Module[]>, source: Modules.Module) {
// TODO push modules
}
}
53 changes: 53 additions & 0 deletions modules/controller-ui/src/assets/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans&display=swap');

:root {
--color-background: #141414;

--color-text: #ffffff;
--color-accent: hsl(177, 100%, 71%);
}

@media (prefers-color-scheme: light) {
:root {
/* TODO: Light theme color */
}
}

body, html {
overscroll-behavior: none;
}

body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition: color 0.5s, background-color 0.5s;
line-height: 1.8;
font-family: 'Nunito Sans', 'Segoe UI', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
font-size: 14px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
margin: 0;
}

::-webkit-scrollbar {
background-color: var(--color-background);
width: 12px;
height: 12px;
}

::-webkit-scrollbar-corner {
background-color: var(--color-background);
}

::-webkit-scrollbar-thumb {
background-color: #272727;
border: 4px solid var(--color-background);
border-radius: 1000px;
transition: 0.3s background-color, 0.3s border;
}

::-webkit-scrollbar-thumb:hover {
background-color: #414141;
}
1 change: 1 addition & 0 deletions modules/controller-ui/src/assets/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './base.css';
20 changes: 20 additions & 0 deletions modules/controller-ui/src/components/Modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export namespace Modules {
export interface ModuleBase<T extends string> {
type: T;
x: number;
y: number;
width: number;
height: number;
}

export interface KeyboardModule extends ModuleBase<"keyboard"> {
channel: number;
}

export interface DrumPadModule extends ModuleBase<"drumpad"> {
channel: number;
matrix: [number, number];
}

export type Module = KeyboardModule | DrumPadModule;
}
Loading

0 comments on commit adf60f0

Please sign in to comment.