-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create bpm input component * add style to the bpm input component and adjust sequencer * modify input value with input or buttons * change bpm while playing beat
- Loading branch information
Showing
8 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
frontend/src/app/components/bpm-input/bpm-input.component.html
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,5 @@ | ||
<div class="number-control"> | ||
<div class="number-left" (click)="decrementBpm()"></div> | ||
<input type="number" name="number" class="number-quantity" [value]="bpm" (change)="updateNumber($event)"> | ||
<div class="number-right" (click)="incrementBpm()"></div> | ||
</div> |
39 changes: 39 additions & 0 deletions
39
frontend/src/app/components/bpm-input/bpm-input.component.scss
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,39 @@ | ||
/* From Uiverse.io by Cybercom682 */ | ||
.number-control { | ||
display: flex; | ||
align-items: center; | ||
|
||
.number-left::before, | ||
.number-right::after { | ||
content: attr(data-content); | ||
background-color: var(--backgroundColor);; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: 1px solid var(--borderColor);; | ||
width: 20px; | ||
color: var(--textColor); | ||
cursor: pointer; | ||
} | ||
|
||
.number-left::before { | ||
content: "-"; | ||
} | ||
|
||
.number-right::after { | ||
content: "+"; | ||
} | ||
|
||
.number-quantity { | ||
padding: 0.25rem; | ||
width: 50px; | ||
height: 12px; | ||
-moz-appearance: textfield; | ||
border: 0; | ||
border-top: 1px solid var(--borderColor); | ||
border-bottom: 1px solid var(--borderColor); | ||
background-color: var(--backgroundColor); | ||
color: var(--textColor); | ||
} | ||
} | ||
|
56 changes: 56 additions & 0 deletions
56
frontend/src/app/components/bpm-input/bpm-input.component.spec.ts
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,56 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BpmInputComponent } from './bpm-input.component'; | ||
import {By} from "@angular/platform-browser"; | ||
|
||
describe('BpmInputComponent', () => { | ||
let component: BpmInputComponent; | ||
let fixture: ComponentFixture<BpmInputComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [BpmInputComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(BpmInputComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should increment the bpm in the desired range', () => { | ||
component.maxBpm = 130; | ||
component.bpm = 128; | ||
component.incrementBpm(); | ||
component.incrementBpm(); | ||
component.incrementBpm(); | ||
expect(component.bpm).toEqual(component.maxBpm); | ||
}); | ||
|
||
it('should decrement the bpm in the desired range', () => { | ||
component.minBpm = 126; | ||
component.bpm = 128; | ||
component.decrementBpm(); | ||
component.decrementBpm(); | ||
component.decrementBpm(); | ||
expect(component.bpm).toEqual(component.minBpm); | ||
}); | ||
|
||
it('should update the value', () => { | ||
component.bpm = 128; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const inputElement = fixture.debugElement.query(By.css('.number-quantity')).nativeElement; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
inputElement.value = '120'; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call | ||
inputElement.dispatchEvent(new Event('change')); | ||
fixture.detectChanges(); | ||
|
||
expect(component.bpm).toBe(120); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
frontend/src/app/components/bpm-input/bpm-input.component.ts
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,37 @@ | ||
import {Component, EventEmitter, Input, Output} from '@angular/core'; | ||
import {SoundService} from "../../services/sound/sound.service"; | ||
|
||
@Component({ | ||
selector: 'app-bpm-input', | ||
standalone: true, | ||
imports: [], | ||
templateUrl: './bpm-input.component.html', | ||
styleUrl: './bpm-input.component.scss' | ||
}) | ||
export class BpmInputComponent { | ||
maxBpm = SoundService.maxBpm; | ||
minBpm = SoundService.minBpm; | ||
@Input() bpm : number = SoundService.minBpm; | ||
@Output() bpmChange = new EventEmitter<number>(); | ||
|
||
incrementBpm() { | ||
this.updateBpm(Math.min(this.bpm+1, this.maxBpm)); | ||
} | ||
|
||
decrementBpm() { | ||
this.updateBpm(Math.max(this.bpm-1, this.minBpm)); | ||
} | ||
|
||
updateNumber(event: Event): void { | ||
const inputElement = event.target as HTMLInputElement; | ||
let value = Number(inputElement.value); | ||
value = Math.min(value, this.maxBpm); | ||
value = Math.max(value, this.minBpm); | ||
this.updateBpm(value); | ||
} | ||
|
||
private updateBpm(value: number): void { | ||
this.bpm = value; | ||
this.bpmChange.emit(this.bpm); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -113,6 +113,10 @@ $gap: 4px; | |
font-weight: bold; | ||
} | ||
} | ||
|
||
div + div { | ||
margin-top: 3px; | ||
} | ||
} | ||
|
||
.play-button-container { | ||
|
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