23 | 23 |
return 1;
|
24 | 24 |
}
|
25 | 25 |
|
|
26 |
static int l_create_session_state(lua_State* L) {
|
|
27 |
abl_link_session_state* session_state = (abl_link_session_state*)lua_newuserdata(L, sizeof(abl_link_session_state));
|
|
28 |
|
|
29 |
*session_state = abl_link_create_session_state();
|
|
30 |
|
|
31 |
luaL_getmetatable(L, "abletonlink.session_state");
|
|
32 |
lua_setmetatable(L, -2);
|
|
33 |
|
|
34 |
return 1;
|
|
35 |
}
|
|
36 |
|
26 | 37 |
static abl_link checklink(lua_State *L) {
|
27 | 38 |
abl_link* link = (abl_link*)luaL_checkudata(L, 1, "abletonlink.link");
|
28 | 39 |
luaL_argcheck(L, link != NULL, 1, "`link' expected");
|
29 | 40 |
luaL_argcheck(L, link->impl != NULL, 1, "`link' is already destroyed");
|
30 | 41 |
return *link;
|
|
42 |
}
|
|
43 |
|
|
44 |
static abl_link_session_state checksessionstate(lua_State *L, int ud) {
|
|
45 |
abl_link_session_state* session_state = (abl_link_session_state*)luaL_checkudata(L, ud, "abletonlink.session_state");
|
|
46 |
luaL_argcheck(L, session_state != NULL, 1, "`session_state' expected");
|
|
47 |
luaL_argcheck(L, session_state->impl != NULL, 1, "`session_state' is already destroyed");
|
|
48 |
return *session_state;
|
31 | 49 |
}
|
32 | 50 |
|
33 | 51 |
static int l_destroy_link(lua_State* L) {
|
|
80 | 98 |
int64_t micros = abl_link_clock_micros(link);
|
81 | 99 |
lua_pushinteger(L, micros);
|
82 | 100 |
return 1;
|
|
101 |
}
|
|
102 |
|
|
103 |
static int l_capture_audio_session_state(lua_State* L) {
|
|
104 |
abl_link link = checklink(L);
|
|
105 |
abl_link_session_state session_state = checksessionstate(L, 2);
|
|
106 |
abl_link_capture_audio_session_state(link, session_state);
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
|
|
110 |
static int l_commit_audio_session_state(lua_State* L) {
|
|
111 |
abl_link link = checklink(L);
|
|
112 |
abl_link_session_state session_state = checksessionstate(L, 2);
|
|
113 |
abl_link_commit_audio_session_state(link, session_state);
|
|
114 |
return 0;
|
|
115 |
}
|
|
116 |
|
|
117 |
static int l_capture_app_session_state(lua_State* L) {
|
|
118 |
abl_link link = checklink(L);
|
|
119 |
abl_link_session_state session_state = checksessionstate(L, 2);
|
|
120 |
abl_link_capture_app_session_state(link, session_state);
|
|
121 |
return 0;
|
|
122 |
}
|
|
123 |
|
|
124 |
static int l_commit_app_session_state(lua_State* L) {
|
|
125 |
abl_link link = checklink(L);
|
|
126 |
abl_link_session_state session_state = checksessionstate(L, 2);
|
|
127 |
abl_link_commit_app_session_state(link, session_state);
|
|
128 |
return 0;
|
83 | 129 |
}
|
84 | 130 |
|
85 | 131 |
static const luaL_Reg abl_link_r[] = {
|
|
90 | 136 |
{ "enable_start_stop_sync", l_enable_start_stop_sync},
|
91 | 137 |
{ "num_peers", l_num_peers },
|
92 | 138 |
{ "clock_micros", l_clock_micros },
|
93 | |
/*
|
94 | 139 |
{ "capture_audio_session_state", l_capture_audio_session_state },
|
95 | 140 |
{ "commit_audio_session_state", l_commit_audio_session_state },
|
96 | 141 |
{ "capture_app_session_state", l_capture_app_session_state },
|
97 | 142 |
{ "commit_app_session_state", l_commit_app_session_state },
|
98 | |
*/
|
99 | 143 |
{ "__gc", l_destroy_link },
|
100 | 144 |
{ NULL, NULL },
|
101 | 145 |
};
|
102 | 146 |
|
103 | |
static abl_link_session_state* checksessionstate(lua_State *L) {
|
104 | |
void *ud = luaL_checkudata(L, 1, "abletonlink.session_state");
|
105 | |
luaL_argcheck(L, ud != NULL, 1, "`session_state' expected");
|
106 | |
return (abl_link_session_state*)ud;
|
107 | |
}
|
108 | |
|
109 | 147 |
static int l_destroy_session_state(lua_State* L) {
|
110 | |
abl_link_session_state* state = checksessionstate(L);
|
111 | |
if (state->impl) {
|
112 | |
abl_link_destroy_session_state(*state);
|
113 | |
state->impl = NULL;
|
|
148 |
abl_link_session_state* session_state = (abl_link_session_state*)luaL_checkudata(L, 1, "abletonlink.session_state");
|
|
149 |
luaL_argcheck(L, session_state != NULL, 1, "`session_state' expected");
|
|
150 |
if (session_state->impl) {
|
|
151 |
abl_link_destroy_session_state(*session_state);
|
|
152 |
session_state->impl = NULL;
|
114 | 153 |
}
|
|
154 |
return 0;
|
|
155 |
}
|
|
156 |
|
|
157 |
static int l_tempo(lua_State* L) {
|
|
158 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
159 |
double bpm = abl_link_tempo(session_state);
|
|
160 |
lua_pushnumber(L, bpm);
|
|
161 |
return 1;
|
|
162 |
}
|
|
163 |
|
|
164 |
static int l_set_tempo(lua_State* L) {
|
|
165 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
166 |
double bpm = luaL_checknumber(L, 2);
|
|
167 |
int64_t at_time = luaL_checkinteger(L, 3);
|
|
168 |
abl_link_set_tempo(session_state, bpm, at_time);
|
|
169 |
return 0;
|
|
170 |
}
|
|
171 |
|
|
172 |
static int l_beat_at_time(lua_State* L) {
|
|
173 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
174 |
int64_t time = luaL_checkinteger(L, 2);
|
|
175 |
double quantum = luaL_checknumber(L, 3);
|
|
176 |
double beat = abl_link_beat_at_time(session_state, time, quantum);
|
|
177 |
lua_pushnumber(L, beat);
|
|
178 |
return 1;
|
|
179 |
}
|
|
180 |
|
|
181 |
static int l_phase_at_time(lua_State* L) {
|
|
182 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
183 |
int64_t time = luaL_checkinteger(L, 2);
|
|
184 |
double quantum = luaL_checknumber(L, 3);
|
|
185 |
double phase = abl_link_phase_at_time(session_state, time, quantum);
|
|
186 |
lua_pushnumber(L, phase);
|
|
187 |
return 1;
|
|
188 |
}
|
|
189 |
|
|
190 |
static int l_time_at_beat(lua_State* L) {
|
|
191 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
192 |
double beat = luaL_checknumber(L, 2);
|
|
193 |
double quantum = luaL_checknumber(L, 3);
|
|
194 |
int64_t time = abl_link_time_at_beat(session_state, beat, quantum);
|
|
195 |
lua_pushinteger(L, time);
|
|
196 |
return 1;
|
|
197 |
}
|
|
198 |
|
|
199 |
static int l_request_beat_at_time(lua_State* L) {
|
|
200 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
201 |
double beat = luaL_checknumber(L, 2);
|
|
202 |
int64_t time = luaL_checkinteger(L, 3);
|
|
203 |
double quantum = luaL_checknumber(L, 4);
|
|
204 |
abl_link_request_beat_at_time(session_state, beat, time, quantum);
|
|
205 |
return 0;
|
|
206 |
}
|
|
207 |
|
|
208 |
static int l_force_beat_at_time(lua_State* L) {
|
|
209 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
210 |
double beat = luaL_checknumber(L, 2);
|
|
211 |
int64_t time = luaL_checkinteger(L, 3);
|
|
212 |
double quantum = luaL_checknumber(L, 4);
|
|
213 |
abl_link_force_beat_at_time(session_state, beat, time, quantum);
|
|
214 |
return 0;
|
|
215 |
}
|
|
216 |
|
|
217 |
static int l_is_playing(lua_State* L) {
|
|
218 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
219 |
bool playing = abl_link_is_playing(session_state);
|
|
220 |
lua_pushboolean(L, playing);
|
|
221 |
return 1;
|
|
222 |
}
|
|
223 |
|
|
224 |
static int l_set_is_playing(lua_State* L) {
|
|
225 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
226 |
bool playing = lua_toboolean(L, 2);
|
|
227 |
int64_t time = luaL_checkinteger(L, 3);
|
|
228 |
abl_link_set_is_playing(session_state, playing, time);
|
|
229 |
return 0;
|
|
230 |
}
|
|
231 |
|
|
232 |
static int l_time_for_is_playing(lua_State* L) {
|
|
233 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
234 |
int64_t time = abl_link_time_for_is_playing(session_state);
|
|
235 |
lua_pushinteger(L, time);
|
|
236 |
return 1;
|
|
237 |
}
|
|
238 |
|
|
239 |
static int l_request_beat_at_start_playing_time(lua_State* L) {
|
|
240 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
241 |
double beat = luaL_checknumber(L, 2);
|
|
242 |
double quantum = luaL_checknumber(L, 3);
|
|
243 |
abl_link_request_beat_at_start_playing_time(session_state, beat, quantum);
|
|
244 |
return 0;
|
|
245 |
}
|
|
246 |
|
|
247 |
static int l_set_is_playing_and_request_beat_at_time(lua_State* L) {
|
|
248 |
abl_link_session_state session_state = checksessionstate(L, 1);
|
|
249 |
bool playing = lua_toboolean(L, 2);
|
|
250 |
int64_t time = luaL_checkinteger(L, 3);
|
|
251 |
double beat = luaL_checknumber(L, 4);
|
|
252 |
double quantum = luaL_checknumber(L, 5);
|
|
253 |
abl_link_set_is_playing_and_request_beat_at_time(session_state, playing, time, beat, quantum);
|
115 | 254 |
return 0;
|
116 | 255 |
}
|
117 | 256 |
|
118 | 257 |
static const luaL_Reg abl_link_session_state_r[] = {
|
119 | 258 |
{ "destroy", l_destroy_session_state },
|
120 | |
/*
|
121 | 259 |
{ "tempo", l_tempo },
|
122 | 260 |
{ "set_tempo", l_set_tempo },
|
123 | 261 |
{ "beat_at_time", l_beat_at_time },
|
|
130 | 268 |
{ "time_for_is_playing", l_time_for_is_playing },
|
131 | 269 |
{ "request_beat_at_start_playing_time", l_request_beat_at_start_playing_time },
|
132 | 270 |
{ "set_is_playing_and_request_beat_at_time", l_set_is_playing_and_request_beat_at_time },
|
133 | |
*/
|
134 | 271 |
{ "__gc", l_destroy_session_state },
|
135 | 272 |
{ NULL, NULL },
|
136 | 273 |
};
|
137 | 274 |
|
138 | 275 |
static const luaL_Reg abletonlink[] = {
|
139 | 276 |
{ "create", l_create_link },
|
|
277 |
{ "create_session_state", l_create_session_state },
|
140 | 278 |
{ NULL, NULL },
|
141 | 279 |
};
|
142 | 280 |
|