Skip to content

Commit 7858498

Browse files
authored
ajout ebm et prise en compte des 16 temps (#25)
1 parent ebd31e0 commit 7858498

File tree

11 files changed

+59
-5
lines changed

11 files changed

+59
-5
lines changed

src/app/components/sequencer/sequencer.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class SequencerComponent implements OnInit {
2828
this.soundService.reset();
2929
this.soundService.setBpm(this.beat.bpm);
3030
this.soundService.setTracks(this.beat.tracks);
31+
this.soundService.setStepNumber(this.beat.tracks[0].steps.length);
3132
});
3233
});
3334
}

src/app/components/sequencer/track/track.component.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div class="track-name">
33
<div>{{ this.name }}</div>
44
</div>
5-
<div id="track">
6-
<div *ngFor="let step of steps; let i = index" class="step" [class.active]="step" [class.current]="i === this.currentStepIndex"></div>
5+
<div id="track" [ngClass]="this.steps.length == 16 ? 'sixteen-steps' : 'thirty-two-steps'">
6+
<div *ngFor="let step of steps; let i = index" class="step" [class.active]="step"
7+
[class.current]="i === this.currentStepIndex"></div>
78
</div>
89
</div>

src/app/components/sequencer/track/track.component.scss

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
#track {
99
display: grid;
10-
grid-template-columns: repeat(16, 1fr);
1110
grid-template-rows: repeat(1, 1fr);
1211
gap: 4px;
1312
}
1413

14+
.sixteen-steps {
15+
grid-template-columns: repeat(16, 1fr);
16+
}
17+
18+
.thirty-two-steps {
19+
grid-template-columns: repeat(32, 1fr);
20+
}
21+
1522
.step {
1623
height: 40px;
1724
width: 40px;

src/app/services/sound.service.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class SoundService {
1313
private context: AudioContext;
1414
private tracks: Track[] = [];
1515
private playbackSource: AudioBufferSourceNode;
16+
private stepNumber: number = 16;
1617

1718
constructor() {
1819
this.context = new AudioContext();
@@ -46,7 +47,7 @@ export class SoundService {
4647

4748
const updateDisplay = () => {
4849
const currentTime = this.context.currentTime - startTime;
49-
this.index = Math.trunc(((currentTime * 1000) / this.getMillisStepFromBpm()) % 16);
50+
this.index = Math.trunc(((currentTime * 1000) / this.getMillisStepFromBpm()) % this.stepNumber);
5051
if (this.isPlaying)
5152
requestAnimationFrame(updateDisplay);
5253
};
@@ -72,7 +73,7 @@ export class SoundService {
7273
//Used to avoid sound clip ;)
7374
async getRenderedBuffer() {
7475
const tickLength = this.getTickLength();
75-
const offlineContext: OfflineAudioContext = new OfflineAudioContext(1, 16 * 2 * tickLength * 44100, 44100);
76+
const offlineContext: OfflineAudioContext = new OfflineAudioContext(1, this.stepNumber * 2 * tickLength * 44100, 44100);
7677
this.tracks.forEach((track: Track) => {
7778
const trackSteps = this.getDuplicatedTrackSteps(track);
7879
trackSteps.forEach((beat: boolean, i: number) => {
@@ -140,4 +141,8 @@ export class SoundService {
140141
private getTickLength() {
141142
return 60 / this.bpm / 4;
142143
};
144+
145+
setStepNumber(length: number) {
146+
this.stepNumber = length;
147+
}
143148
}

src/assets/beats/ebm.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "ebm",
3+
"bpm": 120,
4+
"tracks": [
5+
{
6+
"name": "Clap",
7+
"fileName": "ebm/clap.wav",
8+
"steps": [" ", " ", "X", " ", "X", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", "X", " ", " ", "X", "X", "X", "X", " ", " ", " ", "X", " ", "X", " ", " ", "X", " "]
9+
},
10+
{
11+
"name": "Open High-Hat",
12+
"fileName": "ebm/open-hihat.wav",
13+
"steps": [" ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " "]
14+
},
15+
{
16+
"name": "Closed High-Hat",
17+
"fileName": "ebm/closed-hihat.wav",
18+
"steps": ["X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " ", "X", "X", " ", " "]
19+
},
20+
{
21+
"name": "Snare",
22+
"fileName": "ebm/snare.wav",
23+
"steps": [" ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", "X", " ", "X", "X"]
24+
},
25+
{
26+
"name": "Kick",
27+
"fileName": "ebm/kick.wav",
28+
"steps": ["X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " ", "X", " ", " ", " "]
29+
}
30+
]
31+
}

src/assets/genres.json

+9
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,14 @@
5050
"fileName": "psytrance"
5151
}
5252
]
53+
},
54+
{
55+
"label": "Indus",
56+
"subGenres" : [
57+
{
58+
"label": "EBM",
59+
"fileName": "ebm"
60+
}
61+
]
5362
}
5463
]

src/assets/sounds/ebm/clap.wav

207 KB
Binary file not shown.
207 KB
Binary file not shown.

src/assets/sounds/ebm/kick.wav

207 KB
Binary file not shown.

src/assets/sounds/ebm/open-hihat.wav

207 KB
Binary file not shown.

src/assets/sounds/ebm/snare.wav

379 KB
Binary file not shown.

0 commit comments

Comments
 (0)