Kestrel Interface
Loading...
Searching...
No Matches
kest_profile.c
Go to the documentation of this file.
1#include "kest_int.h"
2
3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
5#endif
6
7static const char *FNAME = "kest_profile.c";
8
10
11static int next_preliminary_profile_id = 1;
12
14{
15 if (!profile)
16 return ERR_NULL_PTR;
17
18 profile->id = 0;
19
20 int ret_val = init_m_pipeline(&profile->pipeline);
21
22 #ifdef KEST_ENABLE_UI
23 profile->view_page = NULL;
24 #endif
25
26 profile->name = NULL;
27 profile->id = next_preliminary_profile_id++;
28
29 profile->fname[0] = 0;
30 profile->has_fname = 0;
31
32 profile->active = 0;
33 profile->unsaved_changes = 1;
34
35 #ifdef KEST_ENABLE_SEQUENCES
36 #ifdef KEST_ENABLE_GLOBAL_CONTEXT
37 profile->sequence = &global_cxt.main_sequence;
38 #else
39 profile->sequence = NULL;
40 #endif
41 #endif
42
43 if (ret_val != NO_ERROR)
44 return ret_val;
45
46 init_parameter(&profile->volume, "Gain", 0.0, -12.0, 12.0);
47 profile->volume.units = " dB";
48 profile->volume.id = (kest_parameter_id){.profile_id = 0, .effect_id = 0xFFFF, .parameter_id = 0};
49
50 #ifdef KEST_ENABLE_REPRESENTATIONS
51 profile->file_rep.representee = profile;
52 profile->file_rep.representer = NULL;
53 profile->file_rep.update = kest_profile_file_rep_update;
54 profile->representations = NULL;
55 kest_representation_pll_safe_append(&profile->representations, &profile->file_rep);
56 #endif
57
58 return NO_ERROR;
59}
60
61int profile_set_id(kest_profile *profile, uint16_t id)
62{
63 if (!profile)
64 return ERR_NULL_PTR;
65
66 profile->id = id;
67 profile->volume.id.profile_id = id;
68
69 return NO_ERROR;
70}
71
73{
74 if (!profile)
75 return ERR_NULL_PTR;
76
77 profile->active = 1;
78
80
82
83 return NO_ERROR;
84}
85
87{
88 if (!profile)
89 return ERR_NULL_PTR;
90
91 profile->active = 0;
92
94
95 return NO_ERROR;
96}
97
99{
100 #ifdef KEST_ENABLE_REPRESENTATIONS
101 if (!profile || !rep)
102 return ERR_NULL_PTR;
103
104 kest_representation_pll *nl = kest_representation_pll_append(profile->representations, rep);
105
106 if (nl)
107 profile->representations = nl;
108 else
109 return ERR_ALLOC_FAIL;
110
111 KEST_PRINTF("profile->representations = %p\n", profile->representations);
112
113 return NO_ERROR;
114 #else
116 #endif
117}
118
120{
121 #ifdef KEST_ENABLE_REPRESENTATIONS
122 if (!profile)
123 return ERR_NULL_PTR;
124
125 if (profile->representations)
126 queue_representation_list_update(profile->representations);
127
128 #endif
129 return NO_ERROR;
130}
131
133{
134 #ifdef KEST_ENABLE_REPRESENTATIONS
135 if (!profile)
136 return ERR_NULL_PTR;
137
138 profile->representations = kest_representation_pll_remove(profile->representations, rep);
139
140 #endif
141 return NO_ERROR;
142}
143
145{
146 KEST_PRINTF("kest_profile_set_default_name_from_id\n");
147 if (!profile)
148 return ERR_NULL_PTR;
149
150 KEST_PRINTF("ID = %d\n", profile->id);
151
152 // Compute the digits in the ID.
153 int id_digits;
154 int id_div = profile->id;
155
156 for (id_digits = 0; id_div || !id_digits; id_div = id_div / 10)
157 id_digits++;
158
159 if (profile->name)
160 kest_free(profile->name);
161
162 profile->name = kest_alloc(9 + id_digits);
163
164 if (!profile->name)
165 return ERR_ALLOC_FAIL;
166
167 sprintf(profile->name, "Profile %d", profile->id);
168
169 KEST_PRINTF("Resulting name: %s\n", profile->name);
170
171 return NO_ERROR;
172}
173
175{
176 if (!profile)
177 return NULL;
178
179 KEST_PRINTF("kest_profile_append_effect_eff(profile = %p, eff = %p)\n", eff);
180 kest_effect *effect = kest_pipeline_append_effect_eff(&profile->pipeline, eff);
181 KEST_PRINTF("effect = %p\n", effect);
182
183 if (!effect)
184 return NULL;
185
187
188 return effect;
189}
190
191int kest_profile_remove_effect(kest_profile *profile, uint16_t id)
192{
193 KEST_PRINTF("kest_profile_remove_effect\n");
194 if (!profile)
195 return ERR_NULL_PTR;
196
197 int ret_val = kest_pipeline_remove_effect(&profile->pipeline, id);
198
200
201 KEST_PRINTF("kest_profile_remove_effect done. ret_val = %s\n", kest_error_code_to_string(ret_val));
202 return ret_val;
203}
204
205int kest_profile_move_effect(kest_profile *profile, int new_pos, int old_pos)
206{
207 int ret_val = NO_ERROR;
208
209 if (profile)
210 {
211 if ((ret_val = kest_pipeline_move_effect(&profile->pipeline, new_pos, old_pos)) != NO_ERROR)
212 return ret_val;
213
214 ret_val = kest_profile_if_active_update_fpga(profile);
215 }
216 else
217 {
218 ret_val = ERR_NULL_PTR;
219 }
220
221 return ret_val;
222}
223
225{
226 if (!src || !dest)
227 return ERR_NULL_PTR;
228
229 KEST_PRINTF("Cloning profile\n");
230
231 KEST_PRINTF("Clone name...\n");
233 clone_parameter(&dest->volume, &src->volume);
234 dest->id = src->id;
235
236 KEST_PRINTF("Clone pipeline...\n");
237 clone_pipeline(&dest->pipeline, &src->pipeline);
238
239 KEST_PRINTF("Done!\n");
240 #ifdef KEST_ENABLE_UI
241 dest->view_page = NULL;
242 #endif
243
244 return NO_ERROR;
245}
246
248{
249 if (!profile)
250 return;
251
252 #ifdef KEST_ENABLE_UI
253 KEST_PRINTF("Gut view page %p...\n", profile->view_page);
254 if (profile->view_page)
255 profile->view_page->free_all(profile->view_page);
256
257 profile->view_page = NULL;
258 #endif
259
260 KEST_PRINTF("Gut name %p...\n", profile->name);
261 if (profile->name)
262 kest_free(profile->name);
263
264 profile->name = NULL;
265
266 KEST_PRINTF("Gut profile...\n");
267 gut_pipeline(&profile->pipeline);
268 KEST_PRINTF("Done!\n");
269}
270
272{
273 if (!profile)
274 return;
275
276 gut_profile(profile);
277
278 kest_free(profile);
279}
280
282{
283 if (!profile)
284 return;
285
286 free_profile(profile);
287
288 return;
289}
290
291#ifdef USE_TEENSY
292void new_profile_receive_id(kest_message msg, kest_response response)
293{
294 kest_profile *profile = msg.cb_arg;
295
296 if (!profile)
297 {
298 KEST_PRINTF("ERROR: Profile ID recieved, but no profile associated !\n");
299 return;
300 }
301
302 uint16_t id;
303 memcpy(&id, response.data, sizeof(uint16_t));
304
305 KEST_PRINTF("New profile recieved its ID: %d\n", id);
306
307 profile_set_id(profile, id);
309
310
312}
313#endif
314
315
317{
318 #ifdef USE_TEENSY
320
321 if (!new_profile)
322 {
323 KEST_PRINTF("ERROR: Couldn't create new profile\n");
324 return NULL;
325 }
326
327 kest_message msg = create_m_message_nodata(KEST_MESSAGE_CREATE_PROFILE);
328
329 msg.callback = new_profile_receive_id;
330 msg.cb_arg = new_profile;
331
332 queue_msg_to_teensy(msg);
333
334 create_profile_view_for(new_profile);
335
336 return new_profile;
337 #else
338 return NULL;
339 #endif
340}
341
342#ifdef KEST_ENABLE_GLOBAL_CONTEXT
343kest_profile *create_new_profile()
344{
346
347 if (!new_profile)
348 {
349 KEST_PRINTF("ERROR: Couldn't create new profile\n");
350 return NULL;
351 }
352
353 #ifdef KEST_ENABLE_UI
354 create_profile_view_for(new_profile);
355 #endif
356
357 return new_profile;
358}
359#endif
360
362{
363 #ifdef KEST_ENABLE_SDCARD
364 if (!profile)
365 return ERR_NULL_PTR;
366
367 int ret_val = save_profile(profile);
368
369 if (ret_val == NO_ERROR)
370 {
371 profile->unsaved_changes = 0;
372 #ifdef KEST_ENABLE_REPRESENTATIONS
374 #endif
375 }
376
377 return NO_ERROR;
378 #else
380 #endif
381}
382
384{
385 if (!profile || !batch)
386 return ERR_NULL_PTR;
387
388 KEST_PRINTF("kest_profile_create_fpga_transfer_batch(profile = %p, batch = %p)\n", profile, batch);
389
390 int ret_val = kest_pipeline_create_fpga_transfer_batch(&profile->pipeline, batch);
391
392 KEST_PRINTF("kest_profile_create_fpga_transfer_batch done (%s)\n", kest_error_code_to_string(ret_val));
393 return ret_val;
394}
395
397{
398 if (!profile)
399 return ERR_NULL_PTR;
400
402
403 #ifndef KEST_LIBRARY
404 KEST_PRINTF("kest_profile_program_fpga\n");
405 int ret_val = kest_pipeline_create_fpga_transfer_batch(&profile->pipeline, &batch);
406
407 KEST_PRINTF("kest_pipeline_create_fpga_transfer_batch returned with error code %s\n", kest_error_code_to_string(ret_val));
408 if (ret_val != NO_ERROR)
409 return ret_val;
410
411 KEST_PRINTF("Queueing transfer batch...\n");
412 if ((ret_val = kest_fpga_queue_program_batch(batch)) != NO_ERROR)
413 {
414 KEST_PRINTF("An error was encountered: %s\n", kest_error_code_to_string(ret_val));
415 return ret_val;
416 }
417 #endif
418
419 return NO_ERROR;
420}
421
423{
424 KEST_PRINTF("kest_profile_if_active_update_fpga");
425 if (!profile)
426 return ERR_NULL_PTR;
427
428 if (!profile->active)
429 return NO_ERROR;
430
431 int ret_val = kest_profile_program_fpga(profile);
432
433 return ret_val;
434}
435
436void kest_profile_file_rep_update(void *representer, void *representee)
437{
438 #ifdef KEST_ENABLE_REPRESENTATIONS
439 if (!representee)
440 return;
441
442 kest_profile *profile = (kest_profile*)representee;
443
444 save_profile(profile);
445 #endif
446 return;
447}
448
449
451{
452 kest_effect *result = kest_pipeline_get_effect_by_id(&profile->pipeline, id);
453
454 return result;
455}
void kest_free(void *ptr)
Definition kest_alloc.c:32
void * kest_alloc(size_t size)
Definition kest_alloc.c:11
char * kest_strndup(const char *str, size_t n)
Definition kest_alloc.c:73
kest_profile * kest_context_add_profile_rp(kest_context *cxt)
int effect_rectify_param_ids(kest_effect *effect)
const char * kest_error_code_to_string(int error_code)
#define ERR_ALLOC_FAIL
#define NO_ERROR
#define ERR_FEATURE_DISABLED
#define ERR_NULL_PTR
int save_profile(kest_profile *profile)
Definition kest_files.c:883
int kest_fpga_queue_program_batch(kest_fpga_transfer_batch batch)
kest_context global_cxt
Definition kest_int.c:12
#define IMPLEMENT_LINKED_PTR_LIST(X)
int init_parameter(kest_parameter *param, const char *name, float level, float min, float max)
void clone_parameter(kest_parameter *dest, kest_parameter *src)
int kest_pipeline_move_effect(kest_pipeline *pipeline, int new_pos, int old_pos)
kest_effect * kest_pipeline_append_effect_eff(kest_pipeline *pipeline, kest_effect_desc *eff)
kest_effect * kest_pipeline_get_effect_by_id(kest_pipeline *pipeline, int id)
int init_m_pipeline(kest_pipeline *pipeline)
int kest_pipeline_remove_effect(kest_pipeline *pipeline, uint16_t id)
int kest_pipeline_create_fpga_transfer_batch(kest_pipeline *pipeline, kest_fpga_transfer_batch *batch)
void gut_pipeline(kest_pipeline *pipeline)
int clone_pipeline(kest_pipeline *dest, kest_pipeline *src)
#define KEST_PRINTF(...)
Definition kest_printf.h:10
int kest_profile_if_active_update_fpga(kest_profile *profile)
int kest_profile_program_fpga(kest_profile *profile)
int kest_profile_remove_effect(kest_profile *profile, uint16_t id)
void kest_profile_file_rep_update(void *representer, void *representee)
kest_effect * kest_profile_get_effect_by_id(kest_profile *profile, int id)
int kest_profile_add_representation(kest_profile *profile, kest_representation *rep)
int init_m_profile(kest_profile *profile)
int clone_profile(kest_profile *dest, kest_profile *src)
int kest_profile_save(kest_profile *profile)
int kest_profile_remove_representation(kest_profile *profile, kest_representation *rep)
void free_profile(kest_profile *profile)
int profile_set_id(kest_profile *profile, uint16_t id)
int kest_profile_update_representations(kest_profile *profile)
int kest_profile_set_active(kest_profile *profile)
kest_profile * create_new_profile_with_teensy()
int kest_profile_set_inactive(kest_profile *profile)
void gut_profile(kest_profile *profile)
void kest_free_profile(kest_profile *profile)
kest_effect * kest_profile_append_effect_eff(kest_profile *profile, kest_effect_desc *eff)
int kest_profile_move_effect(kest_profile *profile, int new_pos, int old_pos)
int kest_profile_create_fpga_transfer_batch(kest_profile *profile, kest_fpga_transfer_batch *batch)
int kest_profile_set_default_name_from_id(kest_profile *profile)
#define PROFILE_NAME_MAX_LEN
Definition kest_profile.h:4
kest_ui_page * create_profile_view_for(kest_profile *profile)
int queue_representation_list_update(kest_representation_pll *reps)
kest_representation_pll * kest_representation_pll_remove(kest_representation_pll *reps, kest_representation *rep)
const char * units
kest_parameter_id id
kest_pipeline pipeline
char fname[KEST_FILENAME_LEN]
kest_parameter volume
uint16_t id