Skip to content

Commit

Permalink
fix: audioDataService
Browse files Browse the repository at this point in the history
  • Loading branch information
AKother committed Feb 21, 2024
1 parent a382d56 commit 3ef9d72
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions spx-gui/src/components/sounds/SoundEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import { nextTick } from "vue";
import { type SimpleWavesurferBackend, WavesurferEdit } from '@/util/wavesurfer-edit'
import { NGradientText, NInput, useMessage, type MessageApi } from "naive-ui";
import { Sound } from '@/class/sound'
import { AudioDataService } from '@/util/wavesurfer-edit-data'
import { audioDataService } from '@/util/wavesurfer-edit-data'
const props = defineProps({
asset: {
Expand Down Expand Up @@ -360,8 +360,8 @@ function isRegionOptionDisabled(): void {
isOperateDisabled.value.copy = !currentRegion;
isOperateDisabled.value.cut = !currentRegion;
isOperateDisabled.value.remove = !currentRegion;
isOperateDisabled.value.paste = !AudioDataService.getCopyData().data;
isOperateDisabled.value.insert = !AudioDataService.getCopyData().data;
isOperateDisabled.value.paste = !audioDataService.getCopyData().data;
isOperateDisabled.value.insert = !audioDataService.getCopyData().data;
}
/* Render wavesurfer */
Expand Down
25 changes: 10 additions & 15 deletions spx-gui/src/util/wavesurfer-edit-data.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
export class AudioDataService {
export const audioDataService = {
copyData: null as AudioBuffer | null,
copyDuration: 0,

private static copyData: AudioBuffer | null = null;
private static copyDuration: number = 0;
setCopyData(data: AudioBuffer, duration: number) {
this.copyData = data;
this.copyDuration = duration;
},

static {
console.log('AudioDataService is loaded');
}

public static setCopyData(data: AudioBuffer, duration: number) {
AudioDataService.copyData = data;
AudioDataService.copyDuration = duration;
}

public static getCopyData(): { data: AudioBuffer | null; duration: number } {
getCopyData(): { data: AudioBuffer | null; duration: number } {
return {
data: AudioDataService.copyData,
duration: AudioDataService.copyDuration,
data: this.copyData,
duration: this.copyDuration,
};
}

Expand Down
20 changes: 10 additions & 10 deletions spx-gui/src/util/wavesurfer-edit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioDataService } from '@/util/wavesurfer-edit-data'
import { audioDataService } from '@/util/wavesurfer-edit-data'

export interface SimpleWavesurferBackend {
buffer?: AudioBuffer;
Expand Down Expand Up @@ -46,8 +46,8 @@ class WavesurferEdit {
this.operationRecord = [this.currentBuffer];
this.operationIndex = 0;
this.currentRegion = null;
this.copyData = AudioDataService.getCopyData().data;
this.copyDuration = AudioDataService.getCopyData().duration;
this.copyData = audioDataService.getCopyData().data;
this.copyDuration = audioDataService.getCopyData().duration;
}

copy(region: Region, buffer: AudioBuffer = this.currentBuffer, isCopy: boolean = true): OperationResult {
Expand All @@ -73,20 +73,20 @@ class WavesurferEdit {
}

if (isCopy) {
AudioDataService.setCopyData(newBuffer, end - start);
audioDataService.setCopyData(newBuffer, end - start);
}

return {
buffer: this.currentBuffer,
curIndex: this.operationIndex,
maxIndex: this.operationRecord.length,
copyData: AudioDataService.getCopyData().data,
copyDuration: AudioDataService.getCopyData().duration,
copyData: audioDataService.getCopyData().data,
copyDuration: audioDataService.getCopyData().duration,
};
}

paste(currentTime: number, buffer: AudioBuffer = this.currentBuffer): OperationResult {
const copyData = AudioDataService.getCopyData();
const copyData = audioDataService.getCopyData();
if (!copyData.data) {
return {
buffer: this.currentBuffer,
Expand Down Expand Up @@ -122,7 +122,7 @@ class WavesurferEdit {
}

insert(currentTime: number, buffer: AudioBuffer = this.currentBuffer): OperationResult {
const copyData = AudioDataService.getCopyData();
const copyData = audioDataService.getCopyData();
if (!copyData.data) {
return {
buffer: this.currentBuffer,
Expand Down Expand Up @@ -199,7 +199,7 @@ class WavesurferEdit {
buffer: newBuffer,
curIndex: this.operationIndex,
maxIndex: this.operationRecord.length,
copyData: AudioDataService.getCopyData().data,
copyData: audioDataService.getCopyData().data,
};
}

Expand All @@ -215,7 +215,7 @@ class WavesurferEdit {
buffer: newBuffer,
curIndex: this.operationIndex,
maxIndex: this.operationRecord.length,
copyData: AudioDataService.getCopyData().data,
copyData: audioDataService.getCopyData().data,
};
}

Expand Down

0 comments on commit 3ef9d72

Please sign in to comment.