C99 port of counterpoint-engine-rs — species counterpoint rule checker with interval classification, first-species rules, and consonance scoring.
- Interval classification — Consonance (perfect/imperfect) and dissonance detection
- First species rules — Parallel 5ths/octaves, voice crossing, leap limits
- Scoring — Consonance ratio minus violation penalties, with configurable thresholds
- Zero dependencies — C99, only
<math.h>and<stdlib.h>
#include "counterpoint_engine.h"
int cf[] = {60, 62, 64, 65, 67}; /* C D E F G */
int cp[] = {64, 65, 67, 69, 71}; /* E F G A B */
VoicePair vp = voice_pair_new(cf, cp, 5);
CounterpointChecker checker = checker_default();
CheckResult result = checker_check(&checker, &vp);
if (check_result_is_valid(&result)) {
printf("Valid! Score: %.2f\n", result.score);
}make # build static library
make test # build and run tests
make clean| Function | Description |
|---|---|
voice_pair_new(cf, cp, n) |
Create a cantus firmus + counterpoint pair |
checker_default() |
Default rule checker |
checker_check(&checker, &vp) |
Evaluate all rules, return CheckResult |
check_result_is_valid(&result) |
Did the pair pass all rules? |
result.score |
Consonance score (higher = better) |
result.violations |
Array of Violation structs |
- counterpoint-engine-rs — The Rust original; this is the C port
- constraint-instrument — Counterpoint rules feed into constraint terrain definitions
- flux-algebra-c — Harmonic analysis for counterpoint evaluation
- creative-engine-c — Chaotic dynamics for generating candidate counterpoint lines
10 tests covering interval classification, consonance detection, parallel fifth/octave rules, voice crossing, and scoring.
make testgit clone https://github.com/SuperInstance/counterpoint-engine-c.git
cd counterpoint-engine-c
makeMIT
Part of the SuperInstance OpenConstruct ecosystem.