Skip to content

Commit

Permalink
Add ability to alias root
Browse files Browse the repository at this point in the history
  • Loading branch information
grsubramanian committed Aug 28, 2021
1 parent ff0ad0f commit 61c6c91
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ $ ./bin/main -s 3 -s 2 -s 2 -s 3 -frets 5
...
```

**Can view how the pattern looks across all 12 frets e.g. sus4 chord sweep**

```
$ ./bin/main -s 5 -s 2 -frets 12
|----|----|----|-4--|----|-5--|----|----|----|----|-1--|----|
|----|----|----|-1--|----|----|----|----|-4--|----|-5--|----|
|-4--|----|-5--|----|----|----|----|-1--|----|----|----|----|
|-1--|----|----|----|----|-4--|----|-5--|----|----|----|----|
|-5--|----|----|----|----|-1--|----|----|----|----|-4--|----|
|----|----|----|-4--|----|-5--|----|----|----|----|-1--|----|
...
```

**Can change guitar tuning - e.g. diminished chord with open tuning**

```
Expand Down Expand Up @@ -117,22 +132,7 @@ $ ./bin/main -s 4 -s 3 -s 2 -ss 7 -ss 5 -ss 4 -ss 3
...
```

**Can rename the 12 notes - e.g. augmented chord**

```
$ ./bin/main -s 4 -s 4 -n "R" -n "b2" -n "2" -n "b3" -n "3" -n "4" -n "#4" -n "5" -n "#5" -n "6" -n "b7" -n "7"
|----|----|----|-R--|
|-3--|----|----|----|
|-R--|----|----|----|
|----|-#5-|----|----|
|----|----|-3--|----|
|----|----|----|-R--|
...
```

**Can rename the 12 notes to a specific key - e.g. C sus 2 chord**
**Can rename the 12 notes to suit typical western notation - e.g. C sus 2 chord**

```
$ ./bin/main -s 2 -s 5 -n "C" -n "Db" -n "D" -n "Eb" -n "E" -n "F" -n "F#" -n "G" -n "Ab" -n "A" -n "Bb" -n "B"
Expand All @@ -147,6 +147,21 @@ $ ./bin/main -s 2 -s 5 -n "C" -n "Db" -n "D" -n "Eb" -n "E" -n "F" -n "F#" -n "G
...
```

**Can pick a specific key - e.g. F augmented chord**

```
$ ./bin/main -r 5 -s 4 -s 4 -n "C" -n "Db" -n "D" -n "Eb" -n "E" -n "F" -n "F#" -n "G" -n "Ab" -n "A" -n "Bb" -n "B"
|----|----|----|-F--|
|-A--|----|----|----|
|-F--|----|----|----|
|----|-Db-|----|----|
|----|----|-A--|----|
|----|----|----|-F--|
...
```

**Can work with any music system - e.g. hypothetical music system with only 7 notes**

```
Expand Down
21 changes: 17 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ func cumSumMod(arr uintslice, maxVal uint) uintslice {
return out
}

func addMod(arr uintslice, toAdd uint, maxVal uint) {
for i, _ := range arr {
arr[i] += toAdd
arr[i] %= maxVal
}
}

func unique(arr uintslice) uintslice {
if len(arr) == 0 {
return arr
Expand Down Expand Up @@ -316,23 +323,28 @@ var defaultStepsBetweenConsecutiveGStrings = uintslice{5, 5, 5, 4, 5}

var stepsBetweenConsecutiveNotesInSequence uintslice

var aliasedRoot uint

var numFretsPerPattern uint

func main() {

flag.Var(&noteRepresentations, "n", "the textual representations of the notes as an ordered list of strings, starting from the representation of the root note. equals " + fmt.Sprintf("%v", defaultNoteRepresentations) + " if not specified.")
flag.Var(&noteRepresentations, "n", "the textual representations of the notes as an ordered list of strings, starting from the representation of the un-aliased (i.e. absolute) root note. equals " + fmt.Sprintf("%v", defaultNoteRepresentations) + " if not specified.")

flag.Var(&stepsBetweenConsecutiveGStrings, "ss", "the tuning represented as an ordered list of non-negative integers. each value represents the step jump from previous frequency string. first value represents jump from the lowest frequency string. equals " + fmt.Sprintf("%v", defaultStepsBetweenConsecutiveGStrings) + " if not specified.")

flag.Var(&stepsBetweenConsecutiveNotesInSequence, "s", "each value represents the step jumps from the previous note in the sequence (chord or scale). first value represents jump from the root note. must specify explicitly.")
flag.Var(&stepsBetweenConsecutiveNotesInSequence, "s", "each value represents the step jumps from the previous note in the sequence (chord or scale). first value represents jump from the aliased root note. must specify explicitly.")

flag.UintVar(&aliasedRoot, "r", uint(0), "the number of steps away from the absolute root to treat as the temporary root. by default, there is no aliasing.")

flag.UintVar(&numFretsPerPattern, "frets", uint(4), "the number of frets per pattern")
flag.Parse()

if len(noteRepresentations) == 0 {
noteRepresentations = defaultNoteRepresentations
}
numNotes := len(noteRepresentations)
aliasedRoot = aliasedRoot % uint(numNotes)

if len(stepsBetweenConsecutiveGStrings) == 0 {
stepsBetweenConsecutiveGStrings = defaultStepsBetweenConsecutiveGStrings
Expand All @@ -347,20 +359,21 @@ func main() {
sequenceNotes := cumSumMod(stepsBetweenConsecutiveNotesInSequence, uint(numNotes))
sort.Sort(sequenceNotes)
sequenceNotes = unique(sequenceNotes)
addMod(sequenceNotes, aliasedRoot, uint(numNotes))

pf := newAsciiPatternPrinter(noteRepresentations)

var lastAcceptedPattern *pattern = nil

for referenceFretOffset := 0; referenceFretOffset < numNotes; referenceFretOffset++ {
rootNoteFretNumOnLowestFrequencyGString := int(numFretsPerPattern) - 1 - referenceFretOffset
referenceNoteFretNumOnLowestFrequencyGString := int(numFretsPerPattern) - 1 - referenceFretOffset

pattern := newPattern()
for gStringNum := 0; gStringNum < numGStrings; gStringNum++ {
gStringPattern := newGStringPattern()

for fretNumOnCurrentString := uint(0); fretNumOnCurrentString < numFretsPerPattern; fretNumOnCurrentString++ {
stepsAwayFromRootNote := (int(stepsAwayFromLowestFrequencyGString[gStringNum] + fretNumOnCurrentString) - rootNoteFretNumOnLowestFrequencyGString) % numNotes
stepsAwayFromRootNote := (int(stepsAwayFromLowestFrequencyGString[gStringNum] + fretNumOnCurrentString + sequenceNotes[0]) - referenceNoteFretNumOnLowestFrequencyGString) % numNotes
if stepsAwayFromRootNote < 0 {
stepsAwayFromRootNote = numNotes + stepsAwayFromRootNote
}
Expand Down

0 comments on commit 61c6c91

Please sign in to comment.