3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Disposable } from 'vs/base/common/lifecycle' ;
6
+ import { Disposable , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
7
7
import { FileAccess } from 'vs/base/common/network' ;
8
8
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
9
9
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
@@ -22,6 +22,8 @@ export interface IAudioCueService {
22
22
onEnabledChanged ( cue : AudioCue ) : Event < void > ;
23
23
24
24
playSound ( cue : Sound , allowManyInParallel ?: boolean ) : Promise < void > ;
25
+ playAudioCueLoop ( cue : AudioCue , milliseconds : number ) : IDisposable ;
26
+ playRandomAudioCue ( groupId : AudioCueGroupId , allowManyInParallel ?: boolean ) : void ;
25
27
}
26
28
27
29
export class AudioCueService extends Disposable implements IAudioCueService {
@@ -51,6 +53,12 @@ export class AudioCueService extends Disposable implements IAudioCueService {
51
53
await Promise . all ( Array . from ( sounds ) . map ( sound => this . playSound ( sound , true ) ) ) ;
52
54
}
53
55
56
+ public playRandomAudioCue ( groupId : AudioCueGroupId , allowManyInParallel ?: boolean ) : void {
57
+ const cues = AudioCue . allAudioCues . filter ( cue => cue . groupId === groupId ) ;
58
+ const index = Math . floor ( Math . random ( ) * cues . length ) ;
59
+ this . playAudioCue ( cues [ index ] , allowManyInParallel ) ;
60
+ }
61
+
54
62
private getVolumeInPercent ( ) : number {
55
63
const volume = this . configurationService . getValue < number > ( 'audioCues.volume' ) ;
56
64
if ( typeof volume !== 'number' ) {
@@ -66,7 +74,6 @@ export class AudioCueService extends Disposable implements IAudioCueService {
66
74
if ( ! allowManyInParallel && this . playingSounds . has ( sound ) ) {
67
75
return ;
68
76
}
69
-
70
77
this . playingSounds . add ( sound ) ;
71
78
const url = FileAccess . asBrowserUri ( `vs/platform/audioCues/browser/media/${ sound . fileName } ` ) . toString ( true ) ;
72
79
@@ -87,6 +94,23 @@ export class AudioCueService extends Disposable implements IAudioCueService {
87
94
}
88
95
}
89
96
97
+ public playAudioCueLoop ( cue : AudioCue , milliseconds : number ) : IDisposable {
98
+ let playing = true ;
99
+ const playSound = ( ) => {
100
+ if ( playing ) {
101
+ this . playAudioCue ( cue , true ) . finally ( ( ) => {
102
+ setTimeout ( ( ) => {
103
+ if ( playing ) {
104
+ playSound ( ) ;
105
+ }
106
+ } , milliseconds ) ;
107
+ } ) ;
108
+ }
109
+ } ;
110
+ playSound ( ) ;
111
+ return toDisposable ( ( ) => playing = false ) ;
112
+ }
113
+
90
114
private readonly obsoleteAudioCuesEnabled = observableFromEvent (
91
115
Event . filter ( this . configurationService . onDidChangeConfiguration , ( e ) =>
92
116
e . affectsConfiguration ( 'audioCues.enabled' )
@@ -190,19 +214,30 @@ export class Sound {
190
214
public static readonly diffLineInserted = Sound . register ( { fileName : 'diffLineInserted.mp3' } ) ;
191
215
public static readonly diffLineDeleted = Sound . register ( { fileName : 'diffLineDeleted.mp3' } ) ;
192
216
public static readonly diffLineModified = Sound . register ( { fileName : 'diffLineModified.mp3' } ) ;
217
+ public static readonly chatRequestSent = Sound . register ( { fileName : 'chatRequestSent.mp3' } ) ;
218
+ public static readonly chatResponsePending = Sound . register ( { fileName : 'chatResponsePending.mp3' } ) ;
219
+ public static readonly chatResponseReceived1 = Sound . register ( { fileName : 'chatResponseReceived1.mp3' } ) ;
220
+ public static readonly chatResponseReceived2 = Sound . register ( { fileName : 'chatResponseReceived2.mp3' } ) ;
221
+ public static readonly chatResponseReceived3 = Sound . register ( { fileName : 'chatResponseReceived3.mp3' } ) ;
222
+ public static readonly chatResponseReceived4 = Sound . register ( { fileName : 'chatResponseReceived4.mp3' } ) ;
223
+ public static readonly chatResponseReceived5 = Sound . register ( { fileName : 'chatResponseReceived5.mp3' } ) ;
193
224
194
225
private constructor ( public readonly fileName : string ) { }
195
226
}
196
227
228
+ export const enum AudioCueGroupId {
229
+ chatResponseReceived = 'chatResponseReceived'
230
+ }
231
+
197
232
export class AudioCue {
198
233
private static _audioCues = new Set < AudioCue > ( ) ;
199
-
200
234
private static register ( options : {
201
235
name : string ;
202
236
sound : Sound ;
203
237
settingsKey : string ;
238
+ groupId ?: AudioCueGroupId ;
204
239
} ) : AudioCue {
205
- const audioCue = new AudioCue ( options . sound , options . name , options . settingsKey ) ;
240
+ const audioCue = new AudioCue ( options . sound , options . name , options . settingsKey , options . groupId ) ;
206
241
AudioCue . _audioCues . add ( audioCue ) ;
207
242
return audioCue ;
208
243
}
@@ -309,9 +344,53 @@ export class AudioCue {
309
344
settingsKey : 'audioCues.diffLineModified'
310
345
} ) ;
311
346
347
+ public static readonly chatRequestSent = AudioCue . register ( {
348
+ name : localize ( 'audioCues.chatRequestSent' , 'Chat Request Sent' ) ,
349
+ sound : Sound . chatRequestSent ,
350
+ settingsKey : 'audioCues.chatRequestSent'
351
+ } ) ;
352
+
353
+ public static readonly chatResponseReceived = {
354
+ name : localize ( 'audioCues.chatResponseReceived' , 'Chat Response Received' ) ,
355
+ settingsKey : 'audioCues.chatResponseReceived' ,
356
+ groupId : AudioCueGroupId . chatResponseReceived
357
+ } ;
358
+
359
+ public static readonly chatResponseReceived1 = AudioCue . register ( {
360
+ sound : Sound . chatResponseReceived1 ,
361
+ ...this . chatResponseReceived
362
+ } ) ;
363
+
364
+ public static readonly chatResponseReceived2 = AudioCue . register ( {
365
+ sound : Sound . chatResponseReceived2 ,
366
+ ...this . chatResponseReceived
367
+ } ) ;
368
+
369
+ public static readonly chatResponseReceived3 = AudioCue . register ( {
370
+ sound : Sound . chatResponseReceived3 ,
371
+ ...this . chatResponseReceived
372
+ } ) ;
373
+
374
+ public static readonly chatResponseReceived4 = AudioCue . register ( {
375
+ sound : Sound . chatResponseReceived4 ,
376
+ ...this . chatResponseReceived
377
+ } ) ;
378
+
379
+ public static readonly chatResponseReceived5 = AudioCue . register ( {
380
+ sound : Sound . chatResponseReceived5 ,
381
+ ...this . chatResponseReceived
382
+ } ) ;
383
+
384
+ public static readonly chatResponsePending = AudioCue . register ( {
385
+ name : localize ( 'audioCues.chatResponsePending' , 'Chat Response Pending' ) ,
386
+ sound : Sound . chatResponsePending ,
387
+ settingsKey : 'audioCues.chatResponsePending'
388
+ } ) ;
389
+
312
390
private constructor (
313
391
public readonly sound : Sound ,
314
392
public readonly name : string ,
315
393
public readonly settingsKey : string ,
394
+ public readonly groupId ?: string
316
395
) { }
317
396
}
0 commit comments