From 033b123ae0f93528847806a5704deabfd3f71464 Mon Sep 17 00:00:00 2001 From: nkymut Date: Tue, 17 Dec 2024 19:22:03 +0800 Subject: [PATCH] Add DOCS for gamepad module --- packages/gamepad/docs/gamepad.mdx | 96 +++++++++++++++++++++++ pnpm-lock.yaml | 24 ++++-- website/src/config.ts | 1 + website/src/pages/learn/input-devices.mdx | 15 ++++ 4 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 packages/gamepad/docs/gamepad.mdx create mode 100644 website/src/pages/learn/input-devices.mdx diff --git a/packages/gamepad/docs/gamepad.mdx b/packages/gamepad/docs/gamepad.mdx new file mode 100644 index 00000000..9fafb072 --- /dev/null +++ b/packages/gamepad/docs/gamepad.mdx @@ -0,0 +1,96 @@ +import { MiniRepl } from '../../../website/src/docs/MiniRepl'; + +# Gamepad + +The Gamepad module allows you to integrate gamepad input functionality into your musical patterns. This can be particularly useful for live performances or interactive installations where you want to manipulate sounds using a game controller. + +## Getting Started + +Initialize a gamepad by calling the gamepad() function with an optional index parameter. + + + +## Available Controls + +The gamepad module provides access to buttons and analog sticks as normalized signals (0-1) that can modulate your patterns. + +### Buttons + +| Type | Controls | +| ---------------- | ---------------------------------------------------------------------------------------------- | +| Face Buttons | `a`, `b`, `x`, `y` (or uppercase `A`, `B`, `X`, `Y`) | +| | Toggle versions: `tglA`, `tglB`, `tglX`, `tglY` | +| Shoulder Buttons | `lb`, `rb`, `lt`, `rt` (or uppercase `LB`, `RB`, `LT`, `RT`) | +| | Toggle versions: `tglLB`, `tglRB`, `tglLT`, `tglRT` | +| D-Pad | `up`, `down`, `left`, `right` (or `u`, `d`, `l`, `r` or uppercase) | +| | Toggle versions: `tglUp`, `tglDown`, `tglLeft`, `tglRight` (or `tglU`, `tglD`, `tglL`, `tglR`) | + +### Analog Sticks + +| Stick | Controls | +| ----------- | ------------------------------ | +| Left Stick | `x1`, `y1` (0 to 1 range) | +| | `x1_2`, `y1_2` (-1 to 1 range) | +| Right Stick | `x2`, `y2` (0 to 1 range) | +| | `x2_2`, `y2_2` (-1 to 1 range) | + +## Using Gamepad Inputs + +Once initialized, you can use various gamepad inputs in your patterns. Here are some examples: + +### Button Inputs + +You can use button inputs to control different aspects of your music, such as gain or triggering events. + + + +### Analog Stick Inputs + +Analog sticks can be used for continuous control, such as pitch shifting or panning. + + + +### Button Sequences + +You can define button sequences to trigger specific actions, like playing a sound when a sequence is detected. + + + +## Multiple Gamepads + +Strudel supports multiple gamepads. You can specify the gamepad index to connect to different devices. + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a18f06e7..61101a77 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -267,6 +267,16 @@ importers: packages/embed: {} + packages/gamepad: + dependencies: + '@strudel/core': + specifier: workspace:* + version: link:../core + devDependencies: + vite: + specifier: ^5.0.10 + version: 5.4.9(@types/node@22.7.6)(terser@5.36.0) + packages/hs2js: dependencies: web-tree-sitter: @@ -614,6 +624,9 @@ importers: '@strudel/draw': specifier: workspace:* version: link:../packages/draw + '@strudel/gamepad': + specifier: workspace:* + version: link:../packages/gamepad '@strudel/hydra': specifier: workspace:* version: link:../packages/hydra @@ -6840,10 +6853,6 @@ packages: resolution: {integrity: sha512-psgxdGMwl5MZM9S3FWee4EgsEaIjahYV5AzGnwUvPhWeITz/j6rKpysQHlQ4USdxvINlb8lKfWGIXwfkrgtqkA==} engines: {node: '>= 10'} - source-map-js@1.0.2: - resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} - engines: {node: '>=0.10.0'} - source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -7740,6 +7749,7 @@ packages: workbox-google-analytics@7.0.0: resolution: {integrity: sha512-MEYM1JTn/qiC3DbpvP2BVhyIH+dV/5BjHk756u9VbwuAhu0QHyKscTnisQuz21lfRpOwiS9z4XdqeVAKol0bzg==} + deprecated: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained workbox-navigation-preload@7.0.0: resolution: {integrity: sha512-juWCSrxo/fiMz3RsvDspeSLGmbgC0U9tKqcUPZBCf35s64wlaLXyn2KdHHXVQrb2cqF7I0Hc9siQalainmnXJA==} @@ -14901,8 +14911,8 @@ snapshots: postcss@8.4.32: dependencies: nanoid: 3.3.7 - picocolors: 1.0.0 - source-map-js: 1.0.2 + picocolors: 1.1.1 + source-map-js: 1.2.1 postcss@8.4.47: dependencies: @@ -15732,8 +15742,6 @@ snapshots: source-map-generator@0.8.0: {} - source-map-js@1.0.2: {} - source-map-js@1.2.1: {} source-map-support@0.5.21: diff --git a/website/src/config.ts b/website/src/config.ts index dd003c18..56b35f6f 100644 --- a/website/src/config.ts +++ b/website/src/config.ts @@ -84,6 +84,7 @@ export const SIDEBAR: Sidebar = { { text: 'Music metadata', link: 'learn/metadata' }, { text: 'CSound', link: 'learn/csound' }, { text: 'Hydra', link: 'learn/hydra' }, + { text: 'Input Devices', link: 'learn/input-devices' }, ], 'Pattern Functions': [ { text: 'Introduction', link: 'functions/intro' }, diff --git a/website/src/pages/learn/input-devices.mdx b/website/src/pages/learn/input-devices.mdx new file mode 100644 index 00000000..62fc0bb5 --- /dev/null +++ b/website/src/pages/learn/input-devices.mdx @@ -0,0 +1,15 @@ +--- +title: Input Devices +layout: ../../layouts/MainLayout.astro +--- + +import { MiniRepl } from '../../docs/MiniRepl'; +import { JsDoc } from '../../docs/JsDoc'; + +import Gamepad from '../../../../packages/gamepad/docs/gamepad.mdx'; + +# Input Devices + +Strudel supports various input devices to enhance your live coding experience and create interactive musical performances. You can use gamepads, mobile device sensors, MIDI controllers, and other input devices to control and modulate your patterns in real-time. This section covers how to integrate different input devices with Strudel and use their signals to create dynamic musical expressions. + +