detector

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 6 Imported by: 1

README

go-chord-detector

Go Report Card go.dev reference

A Go library for detecting and describing musical chords, inspired by Tonal.js and built on go-music-theory.

Usage

import (
    detector "github.com/Golevka2001/go-chord-detector"
    "github.com/go-music-theory/music-theory/note"
)

detector.Detect([]*note.Note{
    note.Named("D"),
    note.Named("F#"),
    note.Named("A"),
    note.Named("C"),
})  // => ["D7"]

// You can also use the note class directly
detector.Detect([]*note.Note{
    {Class: note.E},
    {Class: note.Gs},
    {Class: note.B},
    {Class: note.Cs},
})  // => ["E6", "C#m7/E"]

Options

  • AssumePerfectFifth: if true, the detector will assume that any chord with a third is also a perfect fifth. This is useful for detecting chords with a missing fifth, but can lead to false positives. Default: false.
DetectWithOptions([]*note.Note{
        note.Named("D"),
        note.Named("F"),
        note.Named("C"),
    },
    DetectOptions{AssumePerfectFifth: true},
)  // => ["Dm7"]

DetectWithOptions([]*note.Note{
        note.Named("D"),
        note.Named("F"),
        note.Named("C"),
    },
    DetectOptions{AssumePerfectFifth: false},
)  // => []

License

MIT License

Documentation

Overview

Reference: https://github.com/tonaljs/tonal/tree/main/packages/chord-detect/index.ts

Index

Constants

View Source
const (
	// 3m 000100000000
	// 3M 000010000000
	AnyThirdsMask = 384 // 0b000110000000 = 384
	// 5P 000000010000
	PerfectFifthMask = 16 // 0b000000010000 = 16
	// 5d 000000100000
	// 5A 000000001000
	NonPerfectFifthsMask = 40 // 0b000000101000 = 40
	// 7m 000000000010
	// 7M 000000000001
	AnySeventhMask = 3 // 0b000000000011 = 3
)

Variables

This section is empty.

Functions

func Detect

func Detect(notes []*note.Note) []string

func DetectWithOptions

func DetectWithOptions(source []*note.Note, options DetectOptions) []string

Types

type DetectOptions

type DetectOptions struct {
	AssumePerfectFifth bool
}

type FoundChord

type FoundChord struct {
	Weight float64
	Name   string
}

Directories

Path Synopsis
A dictionary of musical chords.
A dictionary of musical chords.
A pitch class set is a set (no repeated) of pitch classes (notes without octaves).
A pitch class set is a set (no repeated) of pitch classes (notes without octaves).
Reference: https://github.com/tonaljs/tonal/tree/main/packages/pitch-interval/index.ts
Reference: https://github.com/tonaljs/tonal/tree/main/packages/pitch-interval/index.ts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL