Mercurial > vim
annotate src/sound.c @ 26710:8fd8af3764e2
Added tag v8.2.3883 for changeset 0c5daf5e5514e480a99049d77e31249fbfbd6c55
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 Dec 2021 18:00:04 +0100 |
parents | d413104a94c8 |
children | 71137f73c94d |
rev | line source |
---|---|
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * sound.c: functions related making noise |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
16 #if defined(FEAT_SOUND) || defined(PROTO) |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 static long sound_id = 0; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 typedef struct soundcb_S soundcb_T; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 struct soundcb_S { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 callback_T snd_callback; |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
24 #ifdef MSWIN |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
25 MCIDEVICEID snd_device_id; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
26 long snd_id; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
27 #endif |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 soundcb_T *snd_next; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 }; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 static soundcb_T *first_callback = NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
33 /* |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
34 * Return TRUE when a sound callback has been created, it may be invoked when |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
35 * the sound finishes playing. Also see has_sound_callback_in_queue(). |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
36 */ |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
37 int |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
38 has_any_sound_callback(void) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
39 { |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
40 return first_callback != NULL; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
41 } |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
42 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 static soundcb_T * |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 get_sound_callback(typval_T *arg) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 callback_T callback; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 soundcb_T *soundcb; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 if (arg->v_type == VAR_UNKNOWN) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 return NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 callback = get_callback(arg); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 if (callback.cb_name == NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 return NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 soundcb = ALLOC_ONE(soundcb_T); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 if (soundcb == NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 free_callback(&callback); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 else |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 soundcb->snd_next = first_callback; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 first_callback = soundcb; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 set_callback(&soundcb->snd_callback, &callback); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 return soundcb; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 /* |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 * Delete "soundcb" from the list of pending callbacks. |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 */ |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 static void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 delete_sound_callback(soundcb_T *soundcb) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 soundcb_T *p; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 soundcb_T *prev = NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 for (p = first_callback; p != NULL; prev = p, p = p->snd_next) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 if (p == soundcb) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 if (prev == NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 first_callback = p->snd_next; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 else |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 prev->snd_next = p->snd_next; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 free_callback(&p->snd_callback); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 vim_free(p); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 break; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
89 #if defined(HAVE_CANBERRA) || defined(PROTO) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
90 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
91 /* |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
92 * Sound implementation for Linux/Unix/Mac using libcanberra. |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
93 */ |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
94 # include <canberra.h> |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
95 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
96 static ca_context *context = NULL; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
97 |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
98 // Structure to store info about a sound callback to be invoked soon. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
99 typedef struct soundcb_queue_S soundcb_queue_T; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
100 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
101 struct soundcb_queue_S { |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
102 soundcb_queue_T *scb_next; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
103 uint32_t scb_id; // ID of the sound |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
104 int scb_result; // CA_ value |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
105 soundcb_T *scb_callback; // function to call |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
106 }; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
107 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
108 // Queue of callbacks to invoke from the main loop. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
109 static soundcb_queue_T *callback_queue = NULL; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
110 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
111 /* |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
112 * Add a callback to the queue of callbacks to invoke later from the main loop. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
113 * That is because the callback may be called from another thread and invoking |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
114 * another sound function may cause trouble. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
115 */ |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 static void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 sound_callback( |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 ca_context *c UNUSED, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 uint32_t id, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 int error_code, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 void *userdata) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 { |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
123 soundcb_T *soundcb = (soundcb_T *)userdata; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
124 soundcb_queue_T *scb; |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
126 scb = ALLOC_ONE(soundcb_queue_T); |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
127 if (scb == NULL) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
128 return; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
129 scb->scb_next = callback_queue; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
130 callback_queue = scb; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
131 scb->scb_id = id; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
132 scb->scb_result = error_code == CA_SUCCESS ? 0 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 : error_code == CA_ERROR_CANCELED |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 || error_code == CA_ERROR_DESTROYED |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 ? 1 : 2; |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
136 scb->scb_callback = soundcb; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
137 } |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
138 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
139 /* |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
140 * Return TRUE if there is a sound callback to be called. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
141 */ |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
142 int |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
143 has_sound_callback_in_queue(void) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
144 { |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
145 return callback_queue != NULL; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
146 } |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
148 /* |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
149 * Invoke queued sound callbacks. |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
150 */ |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
151 void |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
152 invoke_sound_callback(void) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
153 { |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
154 soundcb_queue_T *scb; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
155 typval_T argv[3]; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
156 typval_T rettv; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
157 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
159 while (callback_queue != NULL) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
160 { |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
161 scb = callback_queue; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
162 callback_queue = scb->scb_next; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
163 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
164 argv[0].v_type = VAR_NUMBER; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
165 argv[0].vval.v_number = scb->scb_id; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
166 argv[1].v_type = VAR_NUMBER; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
167 argv[1].vval.v_number = scb->scb_result; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
168 argv[2].v_type = VAR_UNKNOWN; |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
169 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
170 call_callback(&scb->scb_callback->snd_callback, -1, &rettv, 2, argv); |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
171 clear_tv(&rettv); |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
172 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
173 delete_sound_callback(scb->scb_callback); |
17895
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
174 vim_free(scb); |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17642
diff
changeset
|
175 } |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
176 redraw_after_callback(TRUE, FALSE); |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 static void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 sound_play_common(typval_T *argvars, typval_T *rettv, int playfile) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 { |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
182 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
183 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
184 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 if (context == NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 ca_context_create(&context); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 if (context != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 soundcb_T *soundcb = get_sound_callback(&argvars[1]); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 int res = CA_ERROR_INVALID; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 ++sound_id; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 if (soundcb == NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 res = ca_context_play(context, sound_id, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 playfile ? CA_PROP_MEDIA_FILENAME : CA_PROP_EVENT_ID, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 tv_get_string(&argvars[0]), |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 CA_PROP_CANBERRA_CACHE_CONTROL, "volatile", |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 NULL); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 else |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 static ca_proplist *proplist = NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 ca_proplist_create(&proplist); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 if (proplist != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 if (playfile) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 ca_proplist_sets(proplist, CA_PROP_MEDIA_FILENAME, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 (char *)tv_get_string(&argvars[0])); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 else |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 ca_proplist_sets(proplist, CA_PROP_EVENT_ID, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 (char *)tv_get_string(&argvars[0])); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 ca_proplist_sets(proplist, CA_PROP_CANBERRA_CACHE_CONTROL, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 "volatile"); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 res = ca_context_play_full(context, sound_id, proplist, |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 sound_callback, soundcb); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 if (res != CA_SUCCESS) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 delete_sound_callback(soundcb); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 ca_proplist_destroy(proplist); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 rettv->vval.v_number = res == CA_SUCCESS ? sound_id : 0; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 f_sound_playevent(typval_T *argvars, typval_T *rettv) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 sound_play_common(argvars, rettv, FALSE); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 |
17026
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
234 /* |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
235 * implementation of sound_playfile({path} [, {callback}]) |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
236 */ |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 f_sound_playfile(typval_T *argvars, typval_T *rettv) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 sound_play_common(argvars, rettv, TRUE); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 |
17026
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
243 /* |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
244 * implementation of sound_stop({id}) |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
245 */ |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 f_sound_stop(typval_T *argvars, typval_T *rettv UNUSED) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
249 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
250 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
251 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 if (context != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 ca_context_cancel(context, tv_get_number(&argvars[0])); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 |
17026
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
256 /* |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
257 * implementation of sound_clear() |
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
258 */ |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 void |
17026
905e1b154058
patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
260 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 if (context != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 { |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 ca_context_destroy(context); |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 context = NULL; |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 } |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
269 # if defined(EXITFREE) || defined(PROTO) |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 void |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 sound_free(void) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 { |
17895
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
273 soundcb_queue_T *scb; |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
274 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 if (context != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 ca_context_destroy(context); |
17895
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
277 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 while (first_callback != NULL) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 delete_sound_callback(first_callback); |
17895
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
280 |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
281 while (callback_queue != NULL) |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
282 { |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
283 scb = callback_queue; |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
284 callback_queue = scb->scb_next; |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
285 delete_sound_callback(scb->scb_callback); |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
286 vim_free(scb); |
d55356da47c1
patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
287 } |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 } |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
289 # endif |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
290 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
291 #elif defined(MSWIN) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
292 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
293 /* |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
294 * Sound implementation for MS-Windows. |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
295 */ |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
296 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
297 static HWND g_hWndSound = NULL; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
298 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
299 static LRESULT CALLBACK |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
300 sound_wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
301 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
302 soundcb_T *p; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
303 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
304 switch (message) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
305 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
306 case MM_MCINOTIFY: |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
307 for (p = first_callback; p != NULL; p = p->snd_next) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
308 if (p->snd_device_id == (MCIDEVICEID) lParam) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
309 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
310 typval_T argv[3]; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
311 typval_T rettv; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
312 char buf[32]; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
313 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
314 vim_snprintf(buf, sizeof(buf), "close sound%06ld", |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
315 p->snd_id); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
316 mciSendString(buf, NULL, 0, 0); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
317 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
318 argv[0].v_type = VAR_NUMBER; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
319 argv[0].vval.v_number = p->snd_id; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
320 argv[1].v_type = VAR_NUMBER; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
321 argv[1].vval.v_number = |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
322 wParam == MCI_NOTIFY_SUCCESSFUL ? 0 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
323 : wParam == MCI_NOTIFY_ABORTED ? 1 : 2; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
324 argv[2].v_type = VAR_UNKNOWN; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
325 |
17610
c08a3c552c1d
patch 8.1.1802: missing change to call_callback()
Bram Moolenaar <Bram@vim.org>
parents:
17131
diff
changeset
|
326 call_callback(&p->snd_callback, -1, &rettv, 2, argv); |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
327 clear_tv(&rettv); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
328 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
329 delete_sound_callback(p); |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
330 redraw_after_callback(TRUE, FALSE); |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
331 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
332 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
333 break; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
334 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
335 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
336 return DefWindowProc(hwnd, message, wParam, lParam); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
337 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
338 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
339 static HWND |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
340 sound_window() |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
341 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
342 if (g_hWndSound == NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
343 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
344 LPCSTR clazz = "VimSound"; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
345 WNDCLASS wndclass = { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
346 0, sound_wndproc, 0, 0, g_hinst, NULL, 0, 0, NULL, clazz }; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
347 RegisterClass(&wndclass); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
348 g_hWndSound = CreateWindow(clazz, NULL, 0, 0, 0, 0, 0, |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
349 HWND_MESSAGE, NULL, g_hinst, NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
350 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
351 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
352 return g_hWndSound; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
353 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
354 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
355 void |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
356 f_sound_playevent(typval_T *argvars, typval_T *rettv) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
357 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
358 WCHAR *wp; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
359 |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
360 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
361 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
362 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
363 wp = enc_to_utf16(tv_get_string(&argvars[0]), NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
364 if (wp == NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
365 return; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
366 |
24842
237dace53473
patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
367 if (PlaySoundW(wp, NULL, SND_ASYNC | SND_ALIAS)) |
237dace53473
patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
19049
diff
changeset
|
368 rettv->vval.v_number = ++sound_id; |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
369 free(wp); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
370 } |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
372 void |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
373 f_sound_playfile(typval_T *argvars, typval_T *rettv) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
374 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
375 long newid = sound_id + 1; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
376 size_t len; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
377 char_u *p, *esc; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
378 WCHAR *wp; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
379 soundcb_T *soundcb; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
380 char buf[32]; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
381 MCIERROR err; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
382 |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
383 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
384 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
385 |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
386 esc = vim_strsave_shellescape(tv_get_string(&argvars[0]), FALSE, FALSE); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
387 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
388 len = STRLEN(esc) + 5 + 18 + 1; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
389 p = alloc(len); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
390 if (p == NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
391 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
392 free(esc); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
393 return; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
394 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
395 vim_snprintf((char *)p, len, "open %s alias sound%06ld", esc, newid); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
396 free(esc); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
397 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
398 wp = enc_to_utf16((char_u *)p, NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
399 free(p); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
400 if (wp == NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
401 return; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
402 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
403 err = mciSendStringW(wp, NULL, 0, sound_window()); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
404 free(wp); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
405 if (err != 0) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
406 return; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
407 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
408 vim_snprintf(buf, sizeof(buf), "play sound%06ld notify", newid); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
409 err = mciSendString(buf, NULL, 0, sound_window()); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
410 if (err != 0) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
411 goto failure; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
412 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
413 sound_id = newid; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
414 rettv->vval.v_number = sound_id; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
415 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
416 soundcb = get_sound_callback(&argvars[1]); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
417 if (soundcb != NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
418 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
419 vim_snprintf(buf, sizeof(buf), "sound%06ld", newid); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
420 soundcb->snd_id = newid; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
421 soundcb->snd_device_id = mciGetDeviceID(buf); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
422 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
423 return; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
424 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
425 failure: |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
426 vim_snprintf(buf, sizeof(buf), "close sound%06ld", newid); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
427 mciSendString(buf, NULL, 0, NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
428 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
429 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
430 void |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
431 f_sound_stop(typval_T *argvars, typval_T *rettv UNUSED) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
432 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
433 long id; |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
434 char buf[32]; |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
435 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
436 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
437 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
438 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
439 id = tv_get_number(&argvars[0]); |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
440 vim_snprintf(buf, sizeof(buf), "stop sound%06ld", id); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
441 mciSendString(buf, NULL, 0, NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
442 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
443 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
444 void |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
445 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
446 { |
18006
5594967b38c5
patch 8.1.1999: calling both PlaySoundW() and PlaySoundA()
Bram Moolenaar <Bram@vim.org>
parents:
17895
diff
changeset
|
447 PlaySoundW(NULL, NULL, 0); |
17131
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
448 mciSendString("close all", NULL, 0, NULL); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
449 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
450 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
451 # if defined(EXITFREE) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
452 void |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
453 sound_free(void) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
454 { |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
455 CloseWindow(g_hWndSound); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
456 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
457 while (first_callback != NULL) |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
458 delete_sound_callback(first_callback); |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
459 } |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
460 # endif |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
461 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
462 #endif // MSWIN |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
463 |
be5a5cfc991a
patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents:
17026
diff
changeset
|
464 #endif // FEAT_SOUND |