Skip to content

Commit 3b9e8ec

Browse files
WIP trying to make tunings work
1 parent 3c456fc commit 3b9e8ec

File tree

2 files changed

+69
-9
lines changed

2 files changed

+69
-9
lines changed

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,32 @@
3838

3939
<ng-container
4040
[ngTemplateOutlet]="string"
41-
[ngTemplateOutletContext]="{ stringName: 'e', string: 'E' }"
41+
[ngTemplateOutletContext]="strings[5]"
4242
></ng-container>
4343

4444
<ng-container
4545
[ngTemplateOutlet]="string"
46-
[ngTemplateOutletContext]="{ stringName: 'B', string: 'B' }"
46+
[ngTemplateOutletContext]="strings[4]"
4747
></ng-container>
4848

4949
<ng-container
5050
[ngTemplateOutlet]="string"
51-
[ngTemplateOutletContext]="{ stringName: 'G', string: 'G' }"
51+
[ngTemplateOutletContext]="strings[3]"
5252
></ng-container>
5353

5454
<ng-container
5555
[ngTemplateOutlet]="string"
56-
[ngTemplateOutletContext]="{ stringName: 'D', string: 'D' }"
56+
[ngTemplateOutletContext]="strings[2]"
5757
></ng-container>
5858

5959
<ng-container
6060
[ngTemplateOutlet]="string"
61-
[ngTemplateOutletContext]="{ stringName: 'A', string: 'A' }"
61+
[ngTemplateOutletContext]="strings[1]"
6262
></ng-container>
6363

6464
<ng-container
6565
[ngTemplateOutlet]="string"
66-
[ngTemplateOutletContext]="{ stringName: 'E', string: 'E' }"
66+
[ngTemplateOutletContext]="strings[0]"
6767
></ng-container>
6868
</div>
6969

@@ -111,4 +111,10 @@
111111
(setOrientation)="setOrientation($event)"
112112
></app-fretboard-config>
113113
</div>
114+
115+
<div>
116+
<button (click)="setTuning(Tunings.standard)">standard</button>
117+
<button (click)="setTuning(Tunings.dropD)">drop d</button>
118+
</div>
119+
114120
</div>

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
1+
import {
2+
ChangeDetectorRef,
3+
Component,
4+
ElementRef,
5+
EventEmitter,
6+
Input,
7+
OnChanges,
8+
OnInit,
9+
Output,
10+
ViewChild
11+
} from '@angular/core';
212
import { FretMap, Mode } from '../../../util/types';
313
import { NotePlaybackService } from '../../playback/note-playback.service';
414
import { AbstractDataService } from '../../abstract-data/abstract-data.service';
@@ -19,6 +29,30 @@ export enum NoteDisplays {
1929
noteNames = 'noteNames'
2030
}
2131

32+
enum Tunings {
33+
standard = 'standard',
34+
dropD = 'dropD'
35+
}
36+
37+
const TuningReturner = {
38+
'standard': [
39+
{ stringName: 'E', string: 'E' },
40+
{ stringName: 'A', string: 'A' },
41+
{ stringName: 'D', string: 'D' },
42+
{ stringName: 'G', string: 'G' },
43+
{ stringName: 'B', string: 'B' },
44+
{ stringName: 'e', string: 'E' }
45+
],
46+
'dropD': [
47+
{ stringName: 'D', string: 'D' },
48+
{ stringName: 'A', string: 'A' },
49+
{ stringName: 'D', string: 'D' },
50+
{ stringName: 'G', string: 'G' },
51+
{ stringName: 'B', string: 'B' },
52+
{ stringName: 'e', string: 'E' }
53+
]
54+
};
55+
2256
const FretReturner = {
2357
'twelve': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
2458
'twentyFour': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
@@ -27,7 +61,8 @@ const FretReturner = {
2761
const StorageKeys = {
2862
fretMode: 'fretonator_fretMode',
2963
orientation: 'fretonator_orientation',
30-
noteNameDisplay: 'fretonator_noteNameDisplay'
64+
noteNameDisplay: 'fretonator_noteNameDisplay',
65+
tuning: 'fretonator_tuning'
3166
};
3267

3368
@Component({
@@ -46,19 +81,24 @@ export class FretboardComponent implements OnChanges, OnInit {
4681
orientation;
4782
fretMode;
4883
frets;
84+
strings;
85+
tuning;
4986
highlightedDegrees = new Set<ScaleDegrees>();
5087
noteNameDisplay = NoteDisplays.noteNames;
5188

5289
constructor(public playbackService: NotePlaybackService,
53-
private localStorage: AbstractDataService) {
90+
private localStorage: AbstractDataService,
91+
private cd: ChangeDetectorRef) {
5492
}
5593

5694
ngOnInit() {
5795
this.loadPropFromStorage(StorageKeys.fretMode, 'fretMode', FretModes.twelve);
5896
this.loadPropFromStorage(StorageKeys.orientation, 'orientation', Orientations.right);
5997
this.loadPropFromStorage(StorageKeys.noteNameDisplay, 'noteNameDisplay', NoteDisplays.noteNames);
98+
this.loadPropFromStorage(StorageKeys.tuning, 'tuning', Tunings.standard);
6099

61100
this.toggleHighlight(ScaleDegrees.tonic);
101+
this.configureStrings();
62102
this.configureFretboard();
63103
}
64104

@@ -84,6 +124,14 @@ export class FretboardComponent implements OnChanges, OnInit {
84124
return NoteDisplays;
85125
}
86126

127+
get Tunings() {
128+
return Tunings;
129+
}
130+
131+
configureStrings() {
132+
this.strings = TuningReturner[this.tuning];
133+
}
134+
87135
configureFretboard() {
88136
this.frets = FretReturner[this.fretMode];
89137
this.loadExpandedChange.emit(this.fretMode === FretModes.twentyFour);
@@ -101,6 +149,12 @@ export class FretboardComponent implements OnChanges, OnInit {
101149
this.configureFretboard();
102150
}
103151

152+
setTuning(tuning: Tunings) {
153+
this.tuning = tuning;
154+
this.localStorage.setItem(StorageKeys.tuning, this.tuning);
155+
this.configureStrings();
156+
}
157+
104158
toggleHighlight(degree: ScaleDegrees) {
105159
this.highlightedDegrees.has(degree) ? this.highlightedDegrees.delete(degree) : this.highlightedDegrees.add(degree);
106160
}

0 commit comments

Comments
 (0)