From 24dabca10245716e8f347df4084ce7eb51e74db8 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 20 Dec 2023 11:52:20 +0100 Subject: [PATCH 1/5] pushing some new shortcuts and fixing highlighting --- src/API.ts | 4 ++++ src/documentation/inlineHelp.ts | 28 ++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/API.ts b/src/API.ts index ceb5670..e562a0e 100644 --- a/src/API.ts +++ b/src/API.ts @@ -131,12 +131,15 @@ export class UserAPI { load: samples; public global: { [key: string]: any }; + public g; constructor(public app: Editor) { this.MidiConnection = new MidiConnection(this, app.settings); this.global = {}; + this.g = this.global; } + _loadUniverseFromInterface = (universe: string) => { this.app.selected_universe = universe.trim(); this.app.settings.selected_universe = universe.trim(); @@ -535,6 +538,7 @@ export class UserAPI { */ this.MidiConnection.sendMidiControlChange(control, value, channel); }; + public cc = this.control_change; public midi_panic = (): void => { /** diff --git a/src/documentation/inlineHelp.ts b/src/documentation/inlineHelp.ts index 2c0a8bd..0daf2fb 100644 --- a/src/documentation/inlineHelp.ts +++ b/src/documentation/inlineHelp.ts @@ -733,8 +733,8 @@ const completionDatabase: CompletionDatabase = { midi: { name: "midi", category: "midi", - description: "Send a MIDI message", - example: "midi(144, 60, 100)", + description: "Send a MIDI message (note, velocity, channel)", + example: "midi(144, 60, 1)", }, control_change: { name: "control_change", @@ -742,6 +742,12 @@ const completionDatabase: CompletionDatabase = { description: "Send a MIDI control change message", example: "control_change({control: 1, value: 60, channel: 10})", }, + cc: { + name: "cc", + category: "midi", + description: "Send a MIDI control change message", + example: "cc({control: 1, value: 60, channel: 10})", + }, program_change: { name: "program_change", category: "midi", @@ -808,11 +814,17 @@ const completionDatabase: CompletionDatabase = { description: "Wraps (or not) of the drunk walk (boolean)", example: "drunk_wrap(true)", }, - v: { - name: "v", + global: { + name: "global", category: "variable", description: "Global Variable setter or getter", - example: "v('my_var', 10) // Sets global variable 'my_var' to 10", + example: "global.my_var = 10; // Sets global variable 'my_var' to 10", + }, + g: { + name: "g", + category: "variable", + description: "Global Variable setter or getter", + example: "g.my_var = 10; // Sets global variable 'my_var' to 10", }, delete_variable: { name: "delete_variable", @@ -953,12 +965,12 @@ export const inlineHoveringTips = hoverTooltip( let completion = completionDatabase[text.slice(start - from, end - from)] || {}; let divContent = ` -

${completion.name} [${completion.category}]

+

${completion.name} [${completion.category}]

${completion.description}

${completion.example}
`; let dom = document.createElement("div"); - dom.classList.add("px-4", "py-2", "bg-neutral-700", "rounded-lg"); + dom.classList.add("px-4", "py-2", "bg-background", "rounded-lg"); dom.innerHTML = divContent; return { dom }; }, @@ -978,7 +990,7 @@ export const toposCompletions = (context: CompletionContext) => { info: () => { let div = document.createElement("div"); div.innerHTML = ` -

${completionDatabase[key].name} [${completionDatabase[key].category}]

+

${completionDatabase[key].name} [${completionDatabase[key].category}]

${completionDatabase[key].description}

${completionDatabase[key].example}
`; From 8757d7906af33d66271ce7b24796e795bfbc4743 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 20 Dec 2023 11:58:19 +0100 Subject: [PATCH 2/5] removing some legacy functions --- src/API.ts | 61 ------------------------------------------------------ 1 file changed, 61 deletions(-) diff --git a/src/API.ts b/src/API.ts index 1f70eda..d64d683 100644 --- a/src/API.ts +++ b/src/API.ts @@ -1462,10 +1462,6 @@ export class UserAPI { return this.beat(nums.dur(...nums)); }; - // ============================================================= - // Modulo based time filters - // ============================================================= - // ============================================================= // Other core temporal functions // ============================================================= @@ -1996,38 +1992,6 @@ export class UserAPI { // would be 1.0, which is the current rate (very speedy). }; - // ============================================================= - // Legacy functions - // ============================================================= - - public divseq = (...args: any): any => { - const chunk_size = args[0]; // Get the first argument (chunk size) - const elements = args.slice(1); // Get the rest of the arguments as an array - const timepos = this.app.clock.pulses_since_origin; - const slice_count = Math.floor( - timepos / Math.floor(chunk_size * this.ppqn()), - ); - return elements[slice_count % elements.length]; - }; - - public seqbeat = (...array: T[]): T => { - /** - * Returns an element from an array based on the current beat. - * - * @param array - The array of values to pick from - */ - return array[this.app.clock.time_position.beat % array.length]; - }; - - public seqbar = (...array: T[]): T => { - /** - * Returns an element from an array based on the current bar. - * - * @param array - The array of values to pick from - */ - return array[(this.app.clock.time_position.bar + 1) % array.length]; - }; - // ============================================================= // High Order Functions // ============================================================= @@ -2124,27 +2088,6 @@ export class UserAPI { }; }; - // ============================================================= - // Ralt144mi section - // ============================================================= - - raltfont = (mainFont: string, commentFont: string): void => { - this.app.view.dispatch({ - effects: this.app.fontSize.reconfigure( - EditorView.theme({ - "&": { fontFamily: mainFont }, - ".cm-gutters": { fontFamily: mainFont }, - ".cm-content": { - fontFamily: mainFont, - }, - ".cm-comment": { - fontFamily: commentFont, - }, - }), - ), - }); - }; - // ============================================================= // Resolution // ============================================================= @@ -2946,9 +2889,6 @@ export class UserAPI { return this.randomChar(n, 0x1f910, 0x1f92f); }; - - - // ============================================================= // OSC Functions // ============================================================= @@ -3063,5 +3003,4 @@ export class UserAPI { public getThemes = (): string[] => { return Object.keys(colorschemes); } - } From 6d1624ffd6334f6376b68b8bff3a8c547c58cc49 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 20 Dec 2023 12:00:09 +0100 Subject: [PATCH 3/5] fixing build --- src/API.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/API.ts b/src/API.ts index d64d683..6c73754 100644 --- a/src/API.ts +++ b/src/API.ts @@ -1,4 +1,3 @@ -import { EditorView } from "@codemirror/view"; import { sendToServer, type OSCMessage, oscMessages } from "./IO/OSC"; import { getAllScaleNotes, nearScales, seededRandom } from "zifferjs"; import colorschemes from "./colors.json"; From fd634ee85fd71bd2afe36def5fdf727538f6d2b0 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 20 Dec 2023 12:08:27 +0100 Subject: [PATCH 4/5] fixing nonsensical reference --- src/API.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API.ts b/src/API.ts index 6c73754..fa1072b 100644 --- a/src/API.ts +++ b/src/API.ts @@ -130,7 +130,6 @@ export class UserAPI { load: samples; public global: { [key: string]: any }; - public g; constructor(public app: Editor) { this.MidiConnection = new MidiConnection(this, app.settings); @@ -138,6 +137,7 @@ export class UserAPI { this.g = this.global; } + public g: any; _loadUniverseFromInterface = (universe: string) => { this.app.selected_universe = universe.trim(); From d4fed334ab058fdaed40fe183b54a422edee7245 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Wed, 20 Dec 2023 14:48:49 +0100 Subject: [PATCH 5/5] fixing more highligting issues --- src/EditorSetup.ts | 78 ++++++++++++++++++++++++++++------------------ src/main.ts | 6 +++- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/EditorSetup.ts b/src/EditorSetup.ts index 556ebf3..f15565d 100644 --- a/src/EditorSetup.ts +++ b/src/EditorSetup.ts @@ -123,7 +123,7 @@ export const getCodeMirrorTheme = (theme: {[key: string]: string}): Extension => ".cm-foldPlaceholder": { border: "none", - color: `${blue}`, + color: `${brightwhite}`, }, ".cm-tooltip": { border: "none", @@ -137,7 +137,7 @@ export const getCodeMirrorTheme = (theme: {[key: string]: string}): Extension => ".cm-tooltip-autocomplete": { "& > ul > li[aria-selected]": { backgroundColor: background, - color: background, + color: brightwhite, }, }, }, @@ -201,39 +201,57 @@ export const getCodeMirrorTheme = (theme: {[key: string]: string}): Extension => tag: [t.contentSeparator], color: green, }, - { tag: t.invalid, color: red, borderBottom: `1px dotted ${red}` }, + { + tag: [t.content], + color: brightwhite + }, + { + tag: t.invalid, + color: red, + borderBottom: `1px dotted ${red}` + }, + { + tag: t.null, + color: brightwhite, + } ]); return [ toposTheme, syntaxHighlighting(toposHighlightStyle), ] } -// const debugTheme = EditorView.theme({ -// ".cm-line span": { -// position: "relative", -// }, -// ".cm-line span:hover::after": { -// position: "absolute", -// bottom: "100%", -// left: 0, -// background: "black", -// color: "white", -// border: "solid 2px", -// borderRadius: "5px", -// content: "var(--tags)", -// width: `max-content`, -// padding: "1px 4px", -// zIndex: 10, -// pointerEvents: "none", -// }, -// }); -// -// const debugHighlightStyle = HighlightStyle.define( -// // @ts-ignore -// Object.entries(t).map(([key, value]) => { -// return { tag: value, "--tags": `"tag.${key}"` }; -// }) -// ); -// const debug = [debugTheme, syntaxHighlighting(debugHighlightStyle)]; +const debugTheme = EditorView.theme({ + ".cm-line span": { + position: "relative", + }, + ".cm-line span:hover::after": { + position: "absolute", + bottom: "100%", + left: 0, + background: "black", + color: "white", + border: "solid 2px", + borderRadius: "5px", + content: "var(--tags)", + width: `max-content`, + padding: "1px 4px", + zIndex: 10, + pointerEvents: "none", + }, +}); + +const debugHighlightStyle = HighlightStyle.define( + // @ts-ignore + Object.entries(t).map(([key, value]) => { + return { tag: value, "--tags": `"tag.${key}"` }; + }) +); +const debug = [debugTheme, syntaxHighlighting(debugHighlightStyle)]; + +export const switchToDebugTheme = (app: Editor) => { + app.view.dispatch({ + effects: app.themeCompartment.reconfigure(debug), + }); +} export const jsCompletions = javascriptLanguage.data.of({ diff --git a/src/main.ts b/src/main.ts index 8d165d6..288a50e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,7 @@ import { javascript } from "@codemirror/lang-javascript"; import { markdown } from "@codemirror/lang-markdown"; import { Extension } from "@codemirror/state"; import { outputSocket } from "./IO/OSC"; -import { getCodeMirrorTheme } from "./EditorSetup"; +import { getCodeMirrorTheme, switchToDebugTheme } from "./EditorSetup"; import { initializeSelectedUniverse, AppSettings, @@ -629,6 +629,10 @@ export class Editor { readTheme(theme_name: string): void { // Check if the theme exists in colors.json + if (theme_name == "debug") { + switchToDebugTheme(this); + return + } let themes: Record = colors; let selected_theme = themes[theme_name]; if (selected_theme) {