Skip to content

Commit

Permalink
Support left handed option
Browse files Browse the repository at this point in the history
  • Loading branch information
grsubramanian committed Aug 29, 2021
1 parent 190ee7e commit bcb2255
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,42 @@

<img src="./resources/minor_chord_example.svg">

## Building
## Building the program

```
$ go build -o bin/ cmd/main.go
```
1. Install git on your system. See https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.

2. Install the Go programming language on your system. See https://golang.org/doc/install.

3. Clone this repository. See https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository-from-github/cloning-a-repository.

4. Go into the cloned directory, for example in Unix / Linux systems by running `cd guitar-chord-shapes`.

5. Build the program by running `go build -o bin/ cmd/main.go`.

## Running the program

### Basics

To run the program, just type `./bin/main` with the appropriate command line arguments as will be shown below. This needs to be done from the command line terminal. If you have only used graphical interfaces in the past, this might sound daunting, but it is easy. There are several resources online.

### Available printers

The program will print output to STDOUT. In simple words, this means that the output will print to the screen.

There are two output options available.

* ASCII (default) - lightweight for those who prefer to stay on the terminal.
* SVG (when run with `-svg`) - convenient because the SVG output can be converted to JPG or PNG using free converter tools available online.

If you want the output to go to a file (which you will likely need when using the SVG option), you will need to redirect the output to the file such as `./bin/main -svg {some args} > somefileonthecomputer.svg`.

## Available printers
### Accessibility options

All printers write to STDOUT.
Run with the `-left` argument if you are left handed.

* ASCII (default)
* SVG (when run with `-svg`)
### Use cases

## Use cases
*All examples shown here print in ASCII and use right-handedness.*

**Simple chord - e.g. minor chord**

Expand Down
27 changes: 26 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func (gsp *gStringPattern) add(n *note) {
gsp.notes = append(gsp.notes, n)
}

func (gsp *gStringPattern) mirrored() *gStringPattern {

out := newGStringPattern()
for i := len(gsp.notes) - 1; i >= 0; i -- {
out.add(gsp.notes[i])
}
return out
}

func (gsp *gStringPattern) leftAligned() bool {
return len(gsp.notes) > 0 && gsp.notes[0] != nil
}
Expand Down Expand Up @@ -98,6 +107,14 @@ func (p *pattern) add(gsp *gStringPattern) {
p.gStringPatterns = append(p.gStringPatterns, gsp)
}

func (p *pattern) mirrored() *pattern {
out := newPattern()
for _, gsp := range p.gStringPatterns {
out.add(gsp.mirrored())
}
return out
}

func (p *pattern) leftAligned() bool {
for _, gsp := range p.gStringPatterns {
if gsp.leftAligned() {
Expand Down Expand Up @@ -409,6 +426,8 @@ var aliasedRoot uint

var numFretsPerPattern uint

var leftHanded bool

var printSvg bool

func main() {
Expand All @@ -423,6 +442,8 @@ func main() {

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

flag.BoolVar(&leftHanded, "left", false, "format for lefties")

flag.BoolVar(&printSvg, "svg", false, "whether to print in SVG format")

flag.Parse()
Expand Down Expand Up @@ -484,7 +505,11 @@ func main() {
acceptPattern := pattern.leftAligned() && (pattern.rightAligned() || lastAcceptedPattern == nil || !pattern.rtrim().subPatternOf(lastAcceptedPattern))
if acceptPattern {
lastAcceptedPattern = pattern
pp.accept(pattern)
if leftHanded {
pp.accept(pattern.mirrored())
} else {
pp.accept(pattern)
}
}
}
pp.pprint()
Expand Down

0 comments on commit bcb2255

Please sign in to comment.