@@ -12,6 +12,10 @@ import { Event } from 'vs/base/common/event';
12
12
import { localize } from 'vs/nls' ;
13
13
import { observableFromEvent , derived } from 'vs/base/common/observable' ;
14
14
15
+ export const enum AudioCueGroupId {
16
+ chatResponsePending = 'chatResponsePending'
17
+ }
18
+
15
19
export const IAudioCueService = createDecorator < IAudioCueService > ( 'audioCue' ) ;
16
20
17
21
export interface IAudioCueService {
@@ -23,6 +27,7 @@ export interface IAudioCueService {
23
27
24
28
playSound ( cue : Sound , allowManyInParallel ?: boolean ) : Promise < void > ;
25
29
playAudioCueLoop ( cue : AudioCue ) : IDisposable ;
30
+ playRandomAudioCue ( groupId : AudioCueGroupId , loop ?: boolean ) : IDisposable | void ;
26
31
}
27
32
28
33
export class AudioCueService extends Disposable implements IAudioCueService {
@@ -52,6 +57,16 @@ export class AudioCueService extends Disposable implements IAudioCueService {
52
57
await Promise . all ( Array . from ( sounds ) . map ( sound => this . playSound ( sound , true ) ) ) ;
53
58
}
54
59
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
+
55
70
private getVolumeInPercent ( ) : number {
56
71
const volume = this . configurationService . getValue < number > ( 'audioCues.volume' ) ;
57
72
if ( typeof volume !== 'number' ) {
@@ -209,21 +224,25 @@ export class Sound {
209
224
public static readonly diffLineDeleted = Sound . register ( { fileName : 'diffLineDeleted.mp3' } ) ;
210
225
public static readonly diffLineModified = Sound . register ( { fileName : 'diffLineModified.mp3' } ) ;
211
226
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' } ) ;
213
232
public static readonly chatResponseReceived = Sound . register ( { fileName : 'chatResponseReceived.mp3' } ) ;
214
233
215
234
private constructor ( public readonly fileName : string ) { }
216
235
}
217
236
218
237
export class AudioCue {
219
238
private static _audioCues = new Set < AudioCue > ( ) ;
220
-
221
239
private static register ( options : {
222
240
name : string ;
223
241
sound : Sound ;
224
242
settingsKey : string ;
243
+ groupId ?: AudioCueGroupId ;
225
244
} ) : 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 ) ;
227
246
AudioCue . _audioCues . add ( audioCue ) ;
228
247
return audioCue ;
229
248
}
@@ -336,10 +355,35 @@ export class AudioCue {
336
355
settingsKey : 'audioCues.chatRequestSent'
337
356
} ) ;
338
357
339
- public static readonly chatResponsePending = AudioCue . register ( {
358
+ public static readonly chatResponsePending = {
340
359
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
343
387
} ) ;
344
388
345
389
public static readonly chatResponseReceived = AudioCue . register ( {
@@ -352,5 +396,6 @@ export class AudioCue {
352
396
public readonly sound : Sound ,
353
397
public readonly name : string ,
354
398
public readonly settingsKey : string ,
399
+ public readonly groupId ?: string
355
400
) { }
356
401
}
0 commit comments