Skip to content

Commit

Permalink
Test upload de fichiers locaux #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bludwarf committed Mar 12, 2024
1 parent b7e603f commit f821fbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/app/rythm-sandbox/rythm-sandbox.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
C : <input type="file" accept=".wav,.mp3"/>
B : <input type="file" accept=".wav,.mp3"/>
R : <input type="file" accept=".wav,.mp3"/>

Structure :

<app-structure (clickPattern)="onClickPattern($event)"></app-structure>

<button (click)="play()">Play</button>
<button (click)="stop()">Stop</button>

<br>
<ng-container *ngIf="patternToPlay">
{{patternToPlay}} :
<button (click)="play()" [disabled]="!patternToPlay">Play</button>
<button (click)="stop()" [disabled]="!patternToPlay">Stop</button>
<br>
</ng-container>

<ng-container *ngIf="currentPattern == 'B'">
Partie bombarde :
Expand Down
27 changes: 25 additions & 2 deletions src/app/rythm-sandbox/rythm-sandbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class RythmSandboxComponent {

private player?: Tone.Player;

patternToPlay?: string;

constructor() {
console.log('Events chargés depuis le JSON', events);
}
Expand All @@ -44,16 +46,37 @@ export class RythmSandboxComponent {

await this.stop();

const getAudioFileURL = (pattern: string) => {
const patternIndex = ['C', 'B', 'R'].indexOf(pattern);
if (patternIndex === -1) {
return undefined;
}

const inputElement = document.getElementsByTagName('input');
const file = inputElement?.[patternIndex].files?.[0]
if (!file) {
return undefined;
}

console.log('file', file)
return URL.createObjectURL(file);
};

// const bView = "https://drive.google.com/file/d/1DktZf_rGRaoRxoJEbo3NVWd9yYFX39aj/view?usp=sharing";
// const bDownload = "https://drive.usercontent.google.com/u/0/uc?id=1DktZf_rGRaoRxoJEbo3NVWd9yYFX39aj&export=download";
const audioFiles: Record<string, string> = {
'B': "assets/audio/Petit Papillon/Partie bombarde [2024-01-31 233921].wav",
'C': 'assets/audio/Petit Papillon/PetitPapillon_couplet [2024-01-20 122633].wav',
'R': 'assets/audio/Petit Papillon/Refrain [2024-01-31 233926].wav',
}
const audioFile = audioFiles[this.currentPattern];
// const audioFile = audioFiles[this.currentPattern];

const audioFile = getAudioFileURL(this.currentPattern);
if (!audioFile) {
return;
delete this.patternToPlay
return
} else {
this.patternToPlay = this.currentPattern;
}

const player = new Tone.Player({
Expand Down

0 comments on commit f821fbb

Please sign in to comment.