uSEQ Perform Codebase Tour

Welcome to the uSEQ Perform codebase! This document provides an extensive tour of the codebase structure and functionality to help you understand how the application works and how to extend it.

Overview

uSEQ Perform is a web-based code editor specifically designed for live coding and interacting with hardware and virtual uSEQs. It is written in JavaScript and is based on the CodeMirror 6 editor framework, but it also leverages the ClojureScript-based clojure-mode extension (by NextJournal) for CodeMirror, since ModuLisp is designed to be very similar to Clojure syntactically. Its functionality includes interactive code evaluation, serial communication with hardware devices, a set of key bindings for ease of use while performing, a built-in help mode and others.

Core Technologies

File Structure

Key Components

1. Editor Setup (editorConfig.mjs)

The CodeMirror editor is the heart of the application, customized for Clojure-like syntax and live evaluation:

This module provides:

2. Main Application (main.mjs)

The main module initializes the application, sets up event listeners, and coordinates between components:

This module handles:

3. Serial Communication (serialComms.mjs)

Manages communication with the uSEQ hardware device:

This module provides:

4. Configuration Management (configManager.mjs)

Handles saving and loading user configurations.

5. Panel States (panelStates.mjs)

Manages the visibility and state of UI panels.

Key UI Components

The UI is composed of several panels:

Editor Features

Code Evaluation

The editor supports multiple ways to evaluate code.

These are implemented through CodeMirror’s keymap system in editorConfig.mjs.

Theme Management

Themes can be switched through the UI or programmatically.

Custom Keyboard Shortcuts

Extending the Codebase

Adding a New Feature

  1. Identify which module should contain your feature
  2. Implement your functionality in the appropriate module
  3. Export necessary functions/components
  4. Import and integrate in main.mjs if needed

Adding a New Theme

Add your theme to the themes array in editorConfig.mjs.

Adding New Serial Commands

Extend the serial communication protocol in serialComms.mjs.

Key Customization Points

Advanced Concepts

CodeMirror Extension System

The editor is built on CodeMirror’s extension system. Extensions are objects that add or modify editor behavior.

View Plugin Architecture

CodeMirror uses view plugins to modify the editor behavior.

URL Parameters

The application supports URL parameters for configuration:

Development Workflow

  1. Make changes to source files
  2. Run npm run watch to automatically rebuild on changes
  3. Use npm run dev to start the server and watch for changes

Common Tasks

Adding a New Editor Command

  1. Define a new function in editorConfig.mjs
  2. Add it to the keymap
  3. Export it for use in other modules

Customizing the Editor Appearance

Modify the editorBaseTheme in editorConfig.mjs to change base styling.

Debugging Serial Communication

Use the serial visualization panel to monitor data exchange with the device.

Conclusion

This codebase follows a modular structure with clear separation of concerns. The main components interact through exported functions and events. To understand more about a specific part, start with the corresponding module and follow the imports/exports to see how it integrates with the rest of the application.

For more information on the libraries used, refer to their documentation:

Happy coding!