bugfixing

This commit is contained in:
2020-06-14 15:22:50 +02:00
parent 96566379eb
commit 7578c16188
4 changed files with 11 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {TransposeMode, TransposeService} from './transpose.service'; import {TransposeService} from './transpose.service';
import {TransposeMode} from './transpose-mode';
export enum SectionType { export enum SectionType {
Verse, Verse,

View File

@@ -0,0 +1,4 @@
export interface TransposeMode {
baseKey: string;
targetKey: string
}

View File

@@ -2,11 +2,6 @@ import {Injectable} from '@angular/core';
import {Chord, Line, LineType} from './text-rendering.service'; import {Chord, Line, LineType} from './text-rendering.service';
import {getScaleType, scaleMapping} from './key.helper'; import {getScaleType, scaleMapping} from './key.helper';
export interface TransposeMode {
baseKey: string;
targetKey: string
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@@ -17,7 +12,7 @@ export class TransposeService {
const difference = this.getDistance(baseKey, targetKey); const difference = this.getDistance(baseKey, targetKey);
const map = this.getMap(baseKey, difference); const map = this.getMap(baseKey, difference);
const chords = line.chords.map(chord => this.transposeChord(chord, map)); const chords = difference > 0 ? line.chords.map(chord => this.transposeChord(chord, map)) : line.chords;
const renderedLine = this.renderLine(chords); const renderedLine = this.renderLine(chords);
return {...line, text: renderedLine, chords}; return {...line, text: renderedLine, chords};
@@ -32,14 +27,15 @@ export class TransposeService {
public getDistance(baseKey: string, targetKey: string): number { public getDistance(baseKey: string, targetKey: string): number {
const scale = getScaleType(baseKey); const scale = getScaleType(baseKey);
return ( return scale ? (
(scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey)) ?? (scale[0].indexOf(targetKey) - scale[0].indexOf(baseKey)) ??
(scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey)) (scale[1].indexOf(targetKey) - scale[1].indexOf(baseKey))
) % 12; ) % 12 : 0;
} }
public getMap(baseKey: string, difference: number) { public getMap(baseKey: string, difference: number) {
const scale = getScaleType(baseKey); const scale = getScaleType(baseKey);
if (!scale) return null;
const map = {}; const map = {};
for (let i = 0; i < 12; i++) { for (let i = 0; i < 12; i++) {
const source = scale[0][i]; const source = scale[0][i];

View File

@@ -8,7 +8,7 @@ import {
} from '../../../modules/songs/services/text-rendering.service'; } from '../../../modules/songs/services/text-rendering.service';
import {faGripLines} from '@fortawesome/free-solid-svg-icons/faGripLines'; import {faGripLines} from '@fortawesome/free-solid-svg-icons/faGripLines';
import {songSwitch} from './animation'; import {songSwitch} from './animation';
import {TransposeMode} from '../../../modules/songs/services/transpose.service'; import {TransposeMode} from '../../../modules/songs/services/transpose-mode';
export type ChordMode = 'show' | 'hide' | 'onlyFirst' export type ChordMode = 'show' | 'hide' | 'onlyFirst'