annotate src/sound.c @ 19331:fbd4e8f02f82

Added tag v8.2.0223 for changeset 9c8b803fe5982a003b1dda184e88495e5e7780fa
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Feb 2020 19:30:09 +0100
parents e47b04b01793
children 237dace53473
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
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 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 redraw_after_callback(TRUE);
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 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 if (context == NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 ca_context_create(&context);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 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
187 int res = CA_ERROR_INVALID;
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 ++sound_id;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (soundcb == NULL)
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 res = ca_context_play(context, sound_id,
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 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
194 tv_get_string(&argvars[0]),
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 CA_PROP_CANBERRA_CACHE_CONTROL, "volatile",
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 NULL);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 else
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 static ca_proplist *proplist = NULL;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 ca_proplist_create(&proplist);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 if (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 if (playfile)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 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
207 (char *)tv_get_string(&argvars[0]));
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 else
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 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
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 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
212 "volatile");
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 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
214 sound_callback, soundcb);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 if (res != CA_SUCCESS)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 delete_sound_callback(soundcb);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 ca_proplist_destroy(proplist);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 }
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 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
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
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 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
227 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 sound_play_common(argvars, rettv, FALSE);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
231 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
232 * 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
233 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 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
236 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 sound_play_common(argvars, rettv, TRUE);
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
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
240 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
241 * 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
242 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 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
245 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 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
248 }
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
250 /*
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
251 * 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
252 */
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 void
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
254 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
255 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 {
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 ca_context_destroy(context);
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 context = NULL;
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 }
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
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
263 # if defined(EXITFREE) || defined(PROTO)
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 void
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 sound_free(void)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 {
17895
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
267 soundcb_queue_T *scb;
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
268
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 if (context != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 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
271
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 while (first_callback != NULL)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 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
274
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
275 while (callback_queue != NULL)
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
276 {
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
277 scb = callback_queue;
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
278 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
279 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
280 vim_free(scb);
d55356da47c1 patch 8.1.1944: leaking memory when using sound callback
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
281 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 }
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
283 # endif
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
284
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
285 #elif defined(MSWIN)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
286
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
287 /*
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
288 * Sound implementation for MS-Windows.
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
289 */
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 static HWND g_hWndSound = NULL;
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 static LRESULT CALLBACK
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
294 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
295 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
296 soundcb_T *p;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
297
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
298 switch (message)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
299 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
300 case MM_MCINOTIFY:
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
301 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
302 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
303 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
304 typval_T argv[3];
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
305 typval_T rettv;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
306 char buf[32];
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 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
309 p->snd_id);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
310 mciSendString(buf, NULL, 0, 0);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
311
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
312 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
313 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
314 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
315 argv[1].vval.v_number =
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
316 wParam == MCI_NOTIFY_SUCCESSFUL ? 0
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
317 : 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
318 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
319
17610
c08a3c552c1d patch 8.1.1802: missing change to call_callback()
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
320 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
321 clear_tv(&rettv);
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 delete_sound_callback(p);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
324 redraw_after_callback(TRUE);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
325
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
326 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
327 break;
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
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
330 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
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 static HWND
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
334 sound_window()
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 if (g_hWndSound == NULL)
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 LPCSTR clazz = "VimSound";
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
339 WNDCLASS wndclass = {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
340 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
341 RegisterClass(&wndclass);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
342 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
343 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
344 }
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 return g_hWndSound;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
347 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
348
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
349 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
350 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
351 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
352 WCHAR *wp;
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 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
355 if (wp == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
356 return;
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 PlaySoundW(wp, NULL, SND_ASYNC | SND_ALIAS);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
359 free(wp);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
360
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
361 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
362 }
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
364 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
365 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
366 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
367 long newid = sound_id + 1;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
368 size_t len;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
369 char_u *p, *esc;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
370 WCHAR *wp;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
371 soundcb_T *soundcb;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
372 char buf[32];
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
373 MCIERROR err;
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 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
376
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
377 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
378 p = alloc(len);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
379 if (p == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
380 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
381 free(esc);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
382 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
383 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
384 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
385 free(esc);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
386
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
387 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
388 free(p);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
389 if (wp == NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
390 return;
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 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
393 free(wp);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
394 if (err != 0)
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(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
398 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
399 if (err != 0)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
400 goto failure;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
401
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
402 sound_id = newid;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
403 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
404
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
405 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
406 if (soundcb != NULL)
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), "sound%06ld", newid);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
409 soundcb->snd_id = newid;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
410 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
411 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
412 return;
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
413
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
414 failure:
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
415 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
416 mciSendString(buf, NULL, 0, NULL);
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
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
419 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
420 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
421 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
422 long id = tv_get_number(&argvars[0]);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
423 char buf[32];
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 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
426 mciSendString(buf, NULL, 0, NULL);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
427 }
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 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
430 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
431 {
18006
5594967b38c5 patch 8.1.1999: calling both PlaySoundW() and PlaySoundA()
Bram Moolenaar <Bram@vim.org>
parents: 17895
diff changeset
432 PlaySoundW(NULL, NULL, 0);
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
433 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
434 }
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
435
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
436 # if defined(EXITFREE)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
437 void
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
438 sound_free(void)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
439 {
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
440 CloseWindow(g_hWndSound);
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
441
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
442 while (first_callback != NULL)
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
443 delete_sound_callback(first_callback);
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 # endif
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
446
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
447 #endif // MSWIN
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
448
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
449 #endif // FEAT_SOUND