Chordlock provides multiple interfaces for different use cases.
Interface | Use Case | Performance | Features |
---|---|---|---|
CLI | Command-line usage, testing | Native | Full feature set |
C++ Library | Desktop applications | Native | Core engine |
WebAssembly | Web applications | Near-native | Browser compatibility |
MCP Integration | AI-powered analysis | Network | Claude integration |
Chordlock’s key innovation is key-context aware chord detection:
// Set key context before analysis
detector.setKeyContext(0, false); // C major
detector.setKeyContext(9, true); // A minor
Key context affects:
Chordlock offers multiple detection approaches:
// Basic detection
auto result = detector.detectChord();
// With alternatives
auto result = detector.detectChordWithAlternatives(5);
// With detailed analysis
auto result = detector.detectChordWithDetailedAnalysis(10);
Automatic functional harmony analysis:
// Analyze current notes
auto degree = detector.analyzeCurrentNotesToDegree(tonic, isMinor);
// Analyze specific chord
auto degree = detector.analyzeDegree("Cmaj7", 0, false); // → "I7"
// Generate from degree
auto notes = detector.degreeToNotes("V7", 0, false); // → G7 notes
class MIDIProcessor {
Chordlock detector;
public:
void setKey(int tonic, bool isMinor) {
detector.setKeyContext(tonic, isMinor);
}
void onNoteOn(uint8_t note, uint8_t velocity) {
detector.noteOn(note, velocity);
auto result = detector.detectChord();
if (result.hasValidChord) {
auto degree = detector.analyzeCurrentNotesToDegree(tonic, isMinor);
// Process result...
}
}
};
std::vector<std::string> analyzeProgression(
const std::vector<std::vector<int>>& chords,
int tonic, bool isMinor) {
Chordlock detector;
detector.setKeyContext(tonic, isMinor);
std::vector<std::string> results;
for (const auto& chord : chords) {
detector.clearAllNotes();
for (int note : chord) {
detector.noteOn(note, 80);
}
auto result = detector.detectChord();
auto degree = detector.analyzeCurrentNotesToDegree(tonic, isMinor);
results.push_back(result.chordName + " [" + degree + "]");
}
return results;
}
// Generate chord progression
std::vector<std::string> degrees = {"I", "vi", "IV", "V"};
int tonic = 0; // C major
for (const auto& degree : degrees) {
auto notes = detector.degreeToNotes(degree, tonic, false, 4);
auto chordName = detector.degreeToChordName(degree, tonic, false);
std::cout << degree << " = " << chordName << " = [";
for (size_t i = 0; i < notes.size(); i++) {
std::cout << notes[i];
if (i < notes.size() - 1) std::cout << ", ";
}
std::cout << "]" << std::endl;
}
try {
auto result = detector.detectChord();
if (!result.hasValidChord) {
// Handle no chord detected
}
} catch (const std::exception& e) {
// Handle errors
}
# Exit codes
0 # Success
1 # Invalid arguments
2 # File not found
3 # Invalid key specification
4 # No valid notes found
try {
const result = Module.ccall('chordlock_detect_chord_detailed', 'string', ['number'], [5]);
const data = JSON.parse(result);
if (data.error) {
console.error('Chordlock error:', data.error);
}
} catch (e) {
console.error('Module error:', e);
}
Operation | C++ | WebAssembly | CLI |
---|---|---|---|
Single chord detection | ~0.001ms | ~0.002ms | ~1ms |
With 5 alternatives | ~0.005ms | ~0.010ms | ~2ms |
Roman numeral analysis | ~0.001ms | ~0.002ms | ~0.5ms |
Degree generation | ~0.003ms | ~0.005ms | ~1ms |
Choose your interface and dive into the detailed documentation: