-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
025fbaa
commit 2ec3c2f
Showing
16 changed files
with
149 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package music | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
var noteMap = map[string]int{ | ||
"C": 0, | ||
"Db": 1, | ||
"D": 2, | ||
"Eb": 3, | ||
"E": 4, | ||
"F": 5, | ||
"Gb": 6, | ||
"G": 7, | ||
"Ab": 8, | ||
"A": 9, | ||
"Bb": 10, | ||
"B": 11, | ||
} | ||
|
||
// ConvertNoteToMIDI converts a musical note (ex A6 or Db3) to a midi note number | ||
func ConvertNoteToMIDI(note string) (int, error) { | ||
re := regexp.MustCompile(`^([A-G][b]?)(-?\d+)$`) | ||
matches := re.FindStringSubmatch(note) | ||
if matches == nil || len(matches) < 3 { | ||
return 0, errors.New("invalid note format") | ||
} | ||
|
||
noteName := matches[1] | ||
octaveStr := matches[2] | ||
|
||
octave, err := strconv.Atoi(octaveStr) | ||
if err != nil { | ||
return 0, errors.New("invalid octave") | ||
} | ||
|
||
if base, ok := noteMap[noteName]; ok { | ||
return base + octave*12, nil | ||
} | ||
return 0, errors.New("unknown note name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,5 @@ func (r Root) Set(value int) { | |
} | ||
|
||
func (r Root) SetAlt(value int) {} | ||
|
||
func (r Root) SetEditValue(input string) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,5 @@ func (s Scale) scaleIndex() int { | |
} | ||
return 0 | ||
} | ||
|
||
func (s Scale) SetEditValue(input string) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters