Cobra Music Studio is a single-window app combining a music player, digital audio workstation (DAW), and graphics engine—all built entirely in the KingCobra programming language. It uses only the standard library: std.game for canvas and input, std.music_note for audio synthesis, std.system for files and processes, and std.json for saving state. Source: dev.to.
What It Is
The app merges three functions in one interface: a music player with library, visualizers, and playback controls; a production studio with step sequencer, piano roll, and mixer; and a graphics stack for icons and text. All features are built in about 7,000 lines of KingCobra code.
It does not use std.gui. Instead, the SVG renderer, TrueType font parser, and text/icon systems are all implemented in KingCobra. This gives full control over visuals and performance, avoiding external toolkits and their limitations.
Music Player Features
The library supports search across title, artist, album, and genre. It indexes .wav files in user folders. With ffmpeg, it imports mp3, flac, ogg, m4a, and opus. Favorites, play counts, and lists like recently and most played are included.
Playback is intuitive. Click or drag the waveform to seek. Speed ranges from 0.5x to 1.5x with pitch preserved. Features include shuffle, repeat, sleep timer, and loudness matching that balances volume without clipping.
Without an audio device, it uses system players like pw-play or ffplay. If none are available, it simulates playback with a clock. The app stays usable even on servers.
Production Studio Tools
The step sequencer has eight drum lanes and supports up to eight bars. Users can drag to paint patterns with accents and ghost notes for expressive rhythms.
The piano roll highlights scales, shows note previews, and lets users adjust velocity with the mouse wheel. It includes chord stamps (triad, 7th, power, sus4) and an 808 slide for bassline design.
The mixer supports up to eight tracks. Each has volume, pan, mute, solo, reverb, and sidechain ducking. The kick drum can reduce other tracks for natural dynamics. Presets cover House, Trap, Funk, and Lo-fi. Tools generate random patterns, arpeggios, chord progressions, and basslines.
Editing includes 40-step undo history. Live mode re-renders as you edit. Projects auto-save on crashes and can be reopened. Exports are available in WAV, MIDI, or as individual stems (one WAV per track). Scores can be saved as .kcm files.
Graphics Stack
The graphics engine starts with std.game’s basic canvas and extends it with custom rendering. The SVG parser handles standard path commands (M, L, H, V, C, S, Q, T, A, Z), shapes, groups, transforms, fill, stroke, opacity, and style. It uses exact-area anti-aliasing for visual precision.

The TrueType font parser reads key tables: head, maxp, hhea, hmtx, cmap (formats 4 and 12), loca, and glyf—including composite glyphs. This ensures accurate text rendering across languages.
All glyphs, icons, discs, and rounded corners are stored in one texture atlas. Text is rendered with proportional UTF-8 support in regular, bold, and display weights.
Icons are plain .svg files. They are tinted at draw time using theme colors, like ui.icon("bell", cx, cy, 20, T.accent); .
Design and Architecture
KingCobra creates a separate module instance for every import. This means module-level variables aren’t shared between files. The app avoids conflicts by storing all state in one object passed explicitly between components.
The UI uses an immediate-mode widget toolkit. A single guarded frame loop runs all updates. Every frame is wrapped in error handling. If a bug occurs in any screen, it logs to error.log and playback continues. Repeated faults trigger a fallback to the library screen.
Testing and Development
Tests run the app headlessly. Mouse and keyboard events are injected to simulate real use. There are four test suites with 123 total checks:
- ui_test.kc (38 checks): Covers search, sorting, menus, playback, seeking, volume, EQ, playlists, and persistence.
- studio_test.kc (18 checks): Validates sequencer, piano-roll, undo, rendering, saving, opening, and exporting.
- mature_test.kc (38 checks): Tests velocity, sidechain, sampler, stem exports, drag editing, crash guard, and cache limits.
- gfx_test.kc (29 checks): Ensures SVG accuracy, TrueType parsing, text measurement, and texture atlas performance.
Even the README banner, badges, diagrams, and screenshots are generated by KingCobra programs. This shows a fully self-contained development workflow.
Usage and Limitations
Users need KingCobra 1.0 or later. Audio playback and ffmpeg are optional. Launch with commands like kingcobra run main.kc (1280×720), --size 1600x900 for larger window, KC_MUSIC_SILENT=1 to skip audio, or --headless to render without display.
Music files can be added via Settings or by dropping them into the music/ folder. Press Space to play/pause. Use Left/Right to seek. Press / to search.
Known Limitations
- Changing volume, EQ, or speed causes a re-render, creating a gap of 0.1 to 0.4 seconds when releasing the control.
- Window size is fixed at startup because std.game lacks live-resize support.
- Fonts use only grayscale anti-aliasing with no kerning or hinting, which may reduce clarity at small sizes.
The project is MIT licensed. Fonts are under the SIL Open Font License. Users are encouraged to report issues—especially in audio setups not yet tested—to help improve future versions.
Cobra Music Studio shows how a complete music app can be built from first principles. It offers full self-containment, minimal dependencies, and real-time features without external tools.
Sources & further reading
Featured image: original publisher image. Via original publisher. Image source
