annotate src/sound.c @ 31687:2357c7d1d94f

Added tag v9.0.1175 for changeset 966f1213dd35ffd7cd1fc949988b159f616701b2
author Bram Moolenaar <Bram@vim.org>
date Wed, 11 Jan 2023 13:00:06 +0100
parents 12c0e0f13585
children 543153d582d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
30932
e1e21033c859 patch 9.0.0800: compiler complains about repeated typedef
Bram Moolenaar <Bram@vim.org>
parents: 30719
diff changeset
20 // soundcb_T is typdef'ed in proto/sound.pro
17004
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);
31331
12c0e0f13585 patch 9.0.0999: memory may leak
Bram Moolenaar <Bram@vim.org>
parents: 30932
diff changeset
63 if (callback.cb_free_name)
12c0e0f13585 patch 9.0.0999: memory may leak
Bram Moolenaar <Bram@vim.org>
parents: 30932
diff changeset
64 vim_free(callback.cb_name);
17004
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 return soundcb;
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
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 /*
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
70 * Call "soundcb" with proper parameters.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
71 */
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
72 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
73 call_sound_callback(soundcb_T *soundcb, long snd_id, int result)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
74 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
75 typval_T argv[3];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
76 typval_T rettv;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
77
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
78 argv[0].v_type = VAR_NUMBER;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
79 argv[0].vval.v_number = snd_id;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
80 argv[1].v_type = VAR_NUMBER;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
81 argv[1].vval.v_number = result;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
82 argv[2].v_type = VAR_UNKNOWN;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
83
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
84 call_callback(&soundcb->snd_callback, -1, &rettv, 2, argv);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
85 clear_tv(&rettv);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
86 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
87
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
88 /*
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 * 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
90 */
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
91 void
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 delete_sound_callback(soundcb_T *soundcb)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 soundcb_T *p;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 soundcb_T *prev = NULL;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 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
98 if (p == soundcb)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 if (prev == NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 first_callback = p->snd_next;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 else
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 prev->snd_next = p->snd_next;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 free_callback(&p->snd_callback);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 vim_free(p);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 break;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
110 #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
111
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
112 /*
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
113 * Sound implementation for Linux/Unix using libcanberra.
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
114 */
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
115 # include <canberra.h>
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
116
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
117 static ca_context *context = NULL;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
118
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
119 // 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
120 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
121
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
122 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
123 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
124 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
125 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
126 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
127 };
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
128
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
129 // 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
130 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
131
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
132 /*
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
133 * 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
134 * 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
135 * 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
136 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 static void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 sound_callback(
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 ca_context *c UNUSED,
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 uint32_t id,
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 int error_code,
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 void *userdata)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 {
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
144 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
145 soundcb_queue_T *scb;
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
147 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
148 if (scb == NULL)
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
149 return;
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
150 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
151 callback_queue = scb;
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
152 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
153 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
154 : error_code == CA_ERROR_CANCELED
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 || error_code == CA_ERROR_DESTROYED
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 ? 1 : 2;
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
157 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
158 }
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
159
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 * 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
162 */
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
163 int
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
164 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
165 {
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
166 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
167 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
17708
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 * 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
171 */
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
172 void
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
173 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
174 {
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
175 soundcb_queue_T *scb;
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
177 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
178 {
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
179 scb = callback_queue;
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
180 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
181
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
182 call_sound_callback(scb->scb_callback, scb->scb_id, scb->scb_result);
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
183
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17642
diff changeset
184 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
185 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
186 }
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
187 redraw_after_callback(TRUE, FALSE);
17004
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
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 static void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 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
192 {
25356
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
193 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
194 return;
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
195
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (context == NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 ca_context_create(&context);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 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
201 int res = CA_ERROR_INVALID;
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 ++sound_id;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 if (soundcb == NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 res = ca_context_play(context, sound_id,
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 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
208 tv_get_string(&argvars[0]),
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 CA_PROP_CANBERRA_CACHE_CONTROL, "volatile",
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 NULL);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 else
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 static ca_proplist *proplist = NULL;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 ca_proplist_create(&proplist);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 if (proplist != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (playfile)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 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
221 (char *)tv_get_string(&argvars[0]));
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 else
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 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
224 (char *)tv_get_string(&argvars[0]));
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 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
226 "volatile");
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 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
228 sound_callback, soundcb);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 if (res != CA_SUCCESS)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 delete_sound_callback(soundcb);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 ca_proplist_destroy(proplist);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 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
236 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 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
241 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 sound_play_common(argvars, rettv, FALSE);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
245 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
246 * 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
247 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 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
250 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 sound_play_common(argvars, rettv, TRUE);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
254 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
255 * 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
256 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 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
259 {
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
260 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
261 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
262
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 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
265 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
267 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
268 * 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
269 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 void
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
271 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
272 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 ca_context_destroy(context);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 context = NULL;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
280 # if defined(EXITFREE) || defined(PROTO)
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 sound_free(void)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 {
17895
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
284 soundcb_queue_T *scb;
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
285
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 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
288
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 while (first_callback != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 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
291
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
292 while (callback_queue != NULL)
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
293 {
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
294 scb = callback_queue;
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
295 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
296 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
297 vim_free(scb);
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
298 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 }
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
300 # endif
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 #elif defined(MSWIN)
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 /*
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
305 * Sound implementation for MS-Windows.
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
306 */
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
307
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
308 static HWND g_hWndSound = NULL;
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 static LRESULT CALLBACK
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
311 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
312 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
313 soundcb_T *p;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
314
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
315 switch (message)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
316 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
317 case MM_MCINOTIFY:
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
318 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
319 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
320 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
321 char buf[32];
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
322
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
323 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
324 p->snd_id);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
325 mciSendString(buf, NULL, 0, 0);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
326
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
327 long result = wParam == MCI_NOTIFY_SUCCESSFUL ? 0
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
328 : wParam == MCI_NOTIFY_ABORTED ? 1 : 2;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
329 call_sound_callback(p, p->snd_id, result);
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
330
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
331 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
332 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
333
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 break;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
336 }
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 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
339 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
340
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
341 static HWND
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
342 sound_window()
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 if (g_hWndSound == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
345 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
346 LPCSTR clazz = "VimSound";
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
347 WNDCLASS wndclass = {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
348 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
349 RegisterClass(&wndclass);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
350 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
351 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
352 }
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 return g_hWndSound;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
355 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
356
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
357 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
358 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
359 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
360 WCHAR *wp;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
361
25356
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
362 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
363 return;
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
364
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
365 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
366 if (wp == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
367 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
368
24842
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 19049
diff changeset
369 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
370 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
371 free(wp);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
372 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
374 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
375 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
376 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
377 long newid = sound_id + 1;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
378 size_t len;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
379 char_u *p, *esc;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
380 WCHAR *wp;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
381 soundcb_T *soundcb;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
382 char buf[32];
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
383 MCIERROR err;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
384
25356
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
385 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
386 return;
1cde96e768e4 patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
387
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
388 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
389
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
390 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
391 p = alloc(len);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
392 if (p == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
393 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
394 free(esc);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
395 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
396 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
397 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
398 free(esc);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
399
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
400 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
401 free(p);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
402 if (wp == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
403 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
404
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
405 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
406 free(wp);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
407 if (err != 0)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
408 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
409
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
410 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
411 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
412 if (err != 0)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
413 goto failure;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
414
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
415 sound_id = newid;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
416 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
417
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
418 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
419 if (soundcb != NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
420 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
421 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
422 soundcb->snd_id = newid;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
423 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
424 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
425 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
426
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
427 failure:
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
428 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
429 mciSendString(buf, NULL, 0, NULL);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
430 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
431
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
432 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
433 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
434 {
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
435 long id;
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
436 char buf[32];
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
437
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
438 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
439 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
440
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
441 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
442 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
443 mciSendString(buf, NULL, 0, NULL);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
444 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
445
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
446 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
447 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
448 {
18006
5594967b38c5 patch 8.1.1999: calling both PlaySoundW() and PlaySoundA()
Bram Moolenaar <Bram@vim.org>
parents: 17895
diff changeset
449 PlaySoundW(NULL, NULL, 0);
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
450 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
451 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
452
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
453 # if defined(EXITFREE)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
454 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
455 sound_free(void)
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 CloseWindow(g_hWndSound);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
458
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
459 while (first_callback != NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
460 delete_sound_callback(first_callback);
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
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
463
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
464 #elif defined(MACOS_X_DARWIN)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
465
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
466 // Sound implementation for macOS.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
467 static void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
468 sound_play_common(typval_T *argvars, typval_T *rettv, bool playfile)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
469 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
470 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
471 return;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
472
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
473 char_u *sound_name = tv_get_string(&argvars[0]);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
474 soundcb_T *soundcb = get_sound_callback(&argvars[1]);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
475
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
476 ++sound_id;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
477
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
478 bool play_success = sound_mch_play(sound_name, sound_id, soundcb, playfile);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
479 if (!play_success && soundcb)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
480 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
481 delete_sound_callback(soundcb);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
482 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
483 rettv->vval.v_number = play_success ? sound_id : 0;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
484 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
485
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
486 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
487 f_sound_playevent(typval_T *argvars, typval_T *rettv)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
488 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
489 sound_play_common(argvars, rettv, false);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
490 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
491
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
492 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
493 f_sound_playfile(typval_T *argvars, typval_T *rettv)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
494 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
495 sound_play_common(argvars, rettv, true);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
496 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
497
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
498 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
499 f_sound_stop(typval_T *argvars, typval_T *rettv UNUSED)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
500 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
501 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
502 return;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
503 sound_mch_stop(tv_get_number(&argvars[0]));
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
504 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
505
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
506 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
507 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
508 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
509 sound_mch_clear();
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
510 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
511
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
512 #if defined(EXITFREE) || defined(PROTO)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
513 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
514 sound_free(void)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
515 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
516 sound_mch_free();
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
517 while (first_callback != NULL)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
518 delete_sound_callback(first_callback);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
519 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
520 #endif
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
521
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 26466
diff changeset
522 #endif // MACOS_X_DARWIN
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
523
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
524 #endif // FEAT_SOUND