Skip to content

Commit 4908243

Browse files
committed
use random index
1 parent 9cd42d9 commit 4908243

File tree

9 files changed

+59
-13
lines changed

9 files changed

+59
-13
lines changed

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
8787
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
8888
import { DefaultConfiguration } from 'vs/platform/configuration/common/configurations';
8989
import { WorkspaceEdit } from 'vs/editor/common/languages';
90-
import { AudioCue, IAudioCueService, Sound } from 'vs/platform/audioCues/browser/audioCueService';
90+
import { AudioCue, AudioCueGroupId, IAudioCueService, Sound } from 'vs/platform/audioCues/browser/audioCueService';
9191
import { LogService } from 'vs/platform/log/common/logService';
9292
import { getEditorFeatures } from 'vs/editor/common/editorFeatures';
9393
import { onUnexpectedError } from 'vs/base/common/errors';
@@ -1058,6 +1058,8 @@ class StandaloneAudioService implements IAudioCueService {
10581058
playAudioCueLoop(cue: AudioCue): IDisposable {
10591059
return toDisposable(() => { });
10601060
}
1061+
playRandomAudioCue(groupId: AudioCueGroupId, allowManyInParallel?: boolean | undefined, loop?: boolean): void | IDisposable {
1062+
}
10611063
}
10621064

10631065
export interface IEditorOverrideServices {

src/vs/platform/audioCues/browser/audioCueService.ts

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { Event } from 'vs/base/common/event';
1212
import { localize } from 'vs/nls';
1313
import { observableFromEvent, derived } from 'vs/base/common/observable';
1414

15+
export const enum AudioCueGroupId {
16+
chatResponsePending = 'chatResponsePending'
17+
}
18+
1519
export const IAudioCueService = createDecorator<IAudioCueService>('audioCue');
1620

1721
export interface IAudioCueService {
@@ -23,6 +27,7 @@ export interface IAudioCueService {
2327

2428
playSound(cue: Sound, allowManyInParallel?: boolean): Promise<void>;
2529
playAudioCueLoop(cue: AudioCue): IDisposable;
30+
playRandomAudioCue(groupId: AudioCueGroupId, loop?: boolean): IDisposable | void;
2631
}
2732

2833
export class AudioCueService extends Disposable implements IAudioCueService {
@@ -52,6 +57,16 @@ export class AudioCueService extends Disposable implements IAudioCueService {
5257
await Promise.all(Array.from(sounds).map(sound => this.playSound(sound, true)));
5358
}
5459

60+
public playRandomAudioCue(groupId: AudioCueGroupId, loop?: boolean): void | IDisposable {
61+
const cues = AudioCue.allAudioCues.filter(cue => cue.groupId === groupId);
62+
const index = Math.floor(Math.random() * cues.length);
63+
if (loop) {
64+
return this.playAudioCueLoop(cues[index]);
65+
} else {
66+
this.playAudioCue(cues[index]);
67+
}
68+
}
69+
5570
private getVolumeInPercent(): number {
5671
const volume = this.configurationService.getValue<number>('audioCues.volume');
5772
if (typeof volume !== 'number') {
@@ -209,21 +224,25 @@ export class Sound {
209224
public static readonly diffLineDeleted = Sound.register({ fileName: 'diffLineDeleted.mp3' });
210225
public static readonly diffLineModified = Sound.register({ fileName: 'diffLineModified.mp3' });
211226
public static readonly chatRequestSent = Sound.register({ fileName: 'chatRequestSent.mp3' });
212-
public static readonly chatResponsePending = Sound.register({ fileName: 'chatResponsePending.mp3' });
227+
public static readonly chatResponsePending1 = Sound.register({ fileName: 'chatResponsePending1.mp3' });
228+
public static readonly chatResponsePending2 = Sound.register({ fileName: 'chatResponsePending2.mp3' });
229+
public static readonly chatResponsePending3 = Sound.register({ fileName: 'chatResponsePending3.mp3' });
230+
public static readonly chatResponsePending4 = Sound.register({ fileName: 'chatResponsePending4.mp3' });
231+
public static readonly chatResponsePending5 = Sound.register({ fileName: 'chatResponsePending5.mp3' });
213232
public static readonly chatResponseReceived = Sound.register({ fileName: 'chatResponseReceived.mp3' });
214233

215234
private constructor(public readonly fileName: string) { }
216235
}
217236

218237
export class AudioCue {
219238
private static _audioCues = new Set<AudioCue>();
220-
221239
private static register(options: {
222240
name: string;
223241
sound: Sound;
224242
settingsKey: string;
243+
groupId?: AudioCueGroupId;
225244
}): AudioCue {
226-
const audioCue = new AudioCue(options.sound, options.name, options.settingsKey);
245+
const audioCue = new AudioCue(options.sound, options.name, options.settingsKey, options.groupId);
227246
AudioCue._audioCues.add(audioCue);
228247
return audioCue;
229248
}
@@ -336,10 +355,35 @@ export class AudioCue {
336355
settingsKey: 'audioCues.chatRequestSent'
337356
});
338357

339-
public static readonly chatResponsePending = AudioCue.register({
358+
public static readonly chatResponsePending = {
340359
name: localize('audioCues.chatResponsePending', 'Chat Response Pending'),
341-
sound: Sound.chatResponsePending,
342-
settingsKey: 'audioCues.chatResponsePending'
360+
settingsKey: 'audioCues.chatResponsePending',
361+
groupId: AudioCueGroupId.chatResponsePending
362+
};
363+
364+
public static readonly chatResponsePending1 = AudioCue.register({
365+
sound: Sound.chatResponsePending1,
366+
...this.chatResponsePending
367+
});
368+
369+
public static readonly chatResponsePending2 = AudioCue.register({
370+
sound: Sound.chatResponsePending2,
371+
...this.chatResponsePending
372+
});
373+
374+
public static readonly chatResponsePending3 = AudioCue.register({
375+
sound: Sound.chatResponsePending3,
376+
...this.chatResponsePending
377+
});
378+
379+
public static readonly chatResponsePending4 = AudioCue.register({
380+
sound: Sound.chatResponsePending4,
381+
...this.chatResponsePending
382+
});
383+
384+
public static readonly chatResponsePending5 = AudioCue.register({
385+
sound: Sound.chatResponsePending5,
386+
...this.chatResponsePending
343387
});
344388

345389
public static readonly chatResponseReceived = AudioCue.register({
@@ -352,5 +396,6 @@ export class AudioCue {
352396
public readonly sound: Sound,
353397
public readonly name: string,
354398
public readonly settingsKey: string,
399+
public readonly groupId?: string
355400
) { }
356401
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'vs/css!./media/chat';
1616
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1717
import { localize } from 'vs/nls';
1818
import { MenuId } from 'vs/platform/actions/common/actions';
19-
import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
19+
import { AudioCue, AudioCueGroupId, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
2020
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2121
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2222
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -390,16 +390,15 @@ export class ChatWidget extends Disposable implements IChatWidget {
390390
this.instantiationService.invokeFunction(clearChatSession, this);
391391
return;
392392
}
393-
await this.audioCueService.playAudioCue(AudioCue.chatRequestSent, true);
393+
this.audioCueService.playAudioCue(AudioCue.chatRequestSent, true);
394394
const input = query ?? editorValue;
395-
const cue = this.audioCueService.playAudioCueLoop(AudioCue.chatResponsePending);
395+
const cue = this.audioCueService.playRandomAudioCue(AudioCueGroupId.chatResponsePending, true);
396396
const result = await this.chatService.sendRequest(this.viewModel.sessionId, input);
397-
const audioCueService = this.audioCueService;
398397
if (result) {
399398
this.inputPart.acceptInput(query);
400399
result.responseCompletePromise.then(async () => {
401-
cue.dispose();
402-
audioCueService.playAudioCue(AudioCue.chatResponseReceived, true);
400+
cue?.dispose();
401+
this.audioCueService.playAudioCue(AudioCue.chatResponseReceived, true);
403402
const responses = this.viewModel?.getItems().filter(isResponseVM);
404403
const lastResponse = responses?.[responses.length - 1];
405404
if (lastResponse) {

0 commit comments

Comments
 (0)