Skip to content

agrathwohl/ABCNotationQuark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ABCNotation

A SuperCollider Quark that parses ABC notation into SC3 pattern objects (Pbind, Ppar, Pdef) for use in realtime (JITLib) and offline (NRT) contexts.

ABC parsing is handled by abc2midi, a mature C program. The Quark reads the resulting MIDI and converts it to SuperCollider patterns. You bring your own SynthDefs — MIDI program numbers from %%MIDI program directives map to user-defined instruments via ABCInstrumentMap.

Requirements

  • SuperCollider >= 3.x
  • abc2midi on PATH

NixOS

nix develop   # from the quark directory

Other systems

Install abcmidi from your package manager.

Install

Quarks.install("/path/to/abcNotationQuark");
// recompile class library

Quick Start

s.boot;

// Play ABC directly
ABCParser.play("X:1
T:Scale
M:4/4
L:1/8
Q:1/4=120
K:C
CDEF GABc|c'bag fedc|");

// Or use the String extension
"X:1\nT:Scale\nM:4/4\nL:1/8\nK:C\nCDEF GABc|".playABC;

Usage

Parse and inspect

var score = ABCParser.parseFileSync("/path/to/tune.abc");
score.tune.tracks.do { |t, i|
    "Track %: '%' program=% events=%".format(i, t.name, t.program, t.events.size).postln;
};

Build patterns

var score = ABCParser.parseSync(abcString);

// All voices as Ppar
ABCPatternBuilder.tuneToPpar(score.tune).play;

// Single voice as Pbind
ABCPatternBuilder.trackToPbind(score.tune.tracks[0]).play;

// As a named Pdef
ABCPatternBuilder.tuneToPdef(score.tune, name: \myTune).play;

Instrument mapping

var map = ABCInstrumentMap(\default);
map.put(81, \mySynthLead);
map.putCategory(\bass, \subBass);
map.putCategory(\strings, \padSynth);
map.putDrum(36, \kick);
map.putDrum(38, \snare);

ABCPatternBuilder.tuneToPpar(score.tune, map).play;

JITLib hot-swap

Pdef(\x).play;
Pdef(\x).abc_("X:1\nT:Live\nM:4/4\nL:1/8\nK:C\nCDEF GABc|");

// Swap a single voice from multi-voice ABC
Pdef(\bass).abc_(abcString, voiceIndex: 2);

NRT rendering

var score = ABCParser.parseSync(abcString);
var pattern = ABCPatternBuilder.scoreToPpar(score, map);
pattern.asScore(score.tune.totalDur + 1).recordNRT(
    "/tmp/osc.osc", "/tmp/output.aiff",
    sampleRate: 44100
);

Architecture

ABC string/file
      │
      ▼
  abc2midi (C binary)
      │
      ▼
  Standard MIDI File
      │
      ▼
  ABCMIDIReader (sclang)
      │
      ▼
  ABCScore ──► ABCTune ──► ABCTrack ──► ABCEvent
      │
      ▼
  ABCPatternBuilder
      │
      ├──► Pbind   (single voice)
      ├──► Ppar    (multi-voice)
      └──► Pdef    (JITLib-ready)

Classes

Class Purpose
ABCParser Top-level API. Shells out to abc2midi, reads MIDI, returns ABCScore.
ABCMIDIReader Reads Standard MIDI File binary format into ABCScore.
ABCScore IR container: ABCScoreABCTuneABCTrackABCEvent.
ABCPatternBuilder Converts IR to Pbind/Ppar/Pdef.
ABCInstrumentMap Routes MIDI programs and drum notes to SynthDefs.

Event keys

Patterns produced by ABCPatternBuilder use these Pbind keys:

Key Source
\instrument From ABCInstrumentMap lookup
\midinote MIDI note number (Integer or Array for chords)
\dur Time until next event (beats)
\sustain Sounding duration (beats)
\amp Velocity / 127

License

GPL-3.0

About

A SuperCollider 3 Quark for parsing ABC Notation into SC3 pattern objects

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors