A C++ implementation of Daniel Jones' isobar algorithmic music library.
isobar is a Python library by Daniel Jones, described by its author as "a Python package for creating and manipulating musical patterns, designed for use in algorithmic composition, generative music and sonification". Algorithmic composition means writing rules that generate music, rather than writing every note by hand. isobarcpp is an early start on the same ideas in C++.
So far it has the music theory building blocks: notes, chords, scales and keys, plus number patterns that a composition could step through. It does not make any sound or MIDI yet. When you build it, you get a test program that checks these building blocks and reports which checks pass.
Music Technology and Music:
- How scales, keys and chords can be described with numbers. A C major scale is the semitone steps
0, 2, 4, 5, 7, 9, 11above C. - How MIDI note numbers work: middle C is 60, and each semitone adds 1.
- What a pattern is in algorithmic music: a rule that produces the next value each time you ask, such as "count up by 2" or "repeat this list".
Computer Science:
- Classes and inheritance in C++: every pattern type shares one
Patterninterface withreset()andnext(). - Unit testing with doctest: small checks that prove each piece of code does what it should.
- Building a C++ project with CMake.
You will need:
- Git.
- CMake 3.10 or later, a tool that sets up a C++ build for your computer.
- A C++ compiler:
- Windows: Visual Studio 2022 Community with the "Desktop development with C++" workload.
- macOS: Xcode or its Command Line Tools.
- Linux:
g++orclang++.
The tests depend on doctest, which this repo includes as a git submodule (a link to another repository, fetched along with this one).
Steps:
-
Download the code and the doctest submodule:
git clone --recurse-submodules https://github.com/godofecht/isobarcpp.git cd isobarcppIf you already cloned without
--recurse-submodules, rungit submodule update --initinside the folder. -
Build and run the tests. These are the commands from the original README:
mkdir build cd build cmake .. cmake --build . ctest -C Debug -V
When the test program runs, it ends with this summary:
[doctest] test cases: 12 | 12 passed | 0 failed | 0 skipped
[doctest] assertions: 72 | 72 passed | 0 failed |
[doctest] Status: SUCCESS!
| File or folder | What is in it |
|---|---|
Note.h |
A MIDI note with velocity and duration. toString() turns note 60 into "C4". |
Chord.h |
A chord as a root and a list of intervals. getSemitones() turns intervals {3, 4, 3} into notes {0, 3, 7, 10}. |
Scale.h |
A scale as semitones within an octave. Includes major and minor. |
Key.h |
A key: a tonic note plus a scale. Can name notes, check if a note is in the key, and find the nearest note in the key. |
Pattern.h |
The base class every pattern shares, with reset() and next(). |
Sequence.h |
Pattern types: PSequence, PSeries, PRange, PGeom, PImpulse and PLoop. |
Timeline.h |
Early work on a clock and tracks for playing patterns over time. |
main.cpp |
The BasicProgram target. It is empty for now. |
tests/ |
The doctest tests: test_keys.h, test_chord.h and test_scale.h. |
CMakeLists.txt |
Builds BasicProgram and tests, and registers the tests with CTest. |
- Add a chord test. In
tests/test_chord.h, check thatisobar::Chord({4, 3})gives semitones{0, 4, 7}, a major triad. - Add more scales to
scaleDict()inScale.h, such as the pentatonic scale{0, 2, 4, 7, 9}, and a test for it intests/test_keys.h. - Make
main.cppprint something. Create aPSeries(60, 2, 8)fromSequence.h, callnext()eight times, and print each value as a note name withNote((int) value).toString()fromNote.h. You should see a whole-tone scale starting on C4. - Ambitious: finish
Timeline.hso aTimelineowns aClockand plays a pattern at a set tempo, printing each note as it plays.
- Test framework: doctest 2.4.11, pinned as the submodule
external/doctestat commitae7a135. tests/main.cppdefinesDOCTEST_CONFIG_IMPLEMENT_WITH_MAIN, so doctest suppliesmain(). CTest runs the test executable with--success, which prints passing checks as well as failing ones.- In C++,
-1 % 12is-1, while in Python (which isobar is written in) it is11.Scale.hdefinesScale::floorDivandScale::floorMod, which round the Python way, andScaleandKeyuse them for notes and degrees below 0. - The code compiles as C++11.
CMakeLists.txtdoes not set a C++ standard, so the compiler's default is used. CMakeLists.txtalso defines a custom target,run, that builds and runsBasicProgram.- The pinned doctest asks for CMake 2.8, which CMake 4 refuses.
CMakeLists.txtsetsCMAKE_POLICY_VERSION_MINIMUMto 3.5 before adding it, so it still configures. CMake prints a deprecation warning about doctest, which is harmless. .vscode/tasks.jsonhas a "Run CTest Debug" task that runsctest --output-on-failure --build-config Debugfrombuild/.
From the original README: "Right now, a ton of scaffolding has been written but the tests don't actually pass. The next step is to iterate through each test and debug."
All 12 test cases now pass. The last fixes, in November 2026, were for negative notes in Key.h and Scale.h. The library is still scaffolding. Known problems:
- "Chord Test 1" uses C
assertinstead of doctestCHECK, so doctest does not count its checks. Timelinenever creates itsClock, so callingTimeline::start()will crash.main.cppis empty, and nothing produces sound or MIDI yet.
You can use, copy and change this code for any purpose, as long as you keep the copyright notice. See LICENSE (MIT).
doctest and isobar are both MIT licensed and keep their own copyright. No isobar code is copied here. See THIRD-PARTY-NOTICES.md.