summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/lua/include_lua/sound.lua36
-rw-r--r--apps/plugins/lua/lua.make23
-rwxr-xr-xapps/plugins/lua/rbdefines_helper.pl98
-rw-r--r--apps/plugins/lua/rocklib.c62
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl1
5 files changed, 184 insertions, 36 deletions
diff --git a/apps/plugins/lua/include_lua/sound.lua b/apps/plugins/lua/include_lua/sound.lua
new file mode 100644
index 0000000000..072df0b6ae
--- /dev/null
+++ b/apps/plugins/lua/include_lua/sound.lua
@@ -0,0 +1,36 @@
1--[[ Lua RB sound Operations
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2019 William Wilgus
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22]]
23
24-- [[ conversion to old style sound_ functions ]]
25if not rb.sound then rb.splash(rb.HZ, "No Support!") return nil end
26
27require "sound_defines"
28
29rb.sound_set = function(s, v) return rb.sound("set", s, v) end
30rb.sound_current = function(s) return rb.sound("current", s) end
31rb.sound_default = function(s) return rb.sound("default", s) end
32rb.sound_min = function(s) return rb.sound("min", s) end
33rb.sound_max = function(s) return rb.sound("max", s) end
34rb.sound_unit = function(s) return rb.sound("unit", s) end
35rb.sound_pitch = function(s) return rb.sound("pitch", s) end
36rb.sound_val2phys = function(s, v) return rb.sound("val2phys", s, v) end
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index f54d35bc44..16e25c3028 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -17,7 +17,9 @@ OTHER_SRC += $(LUA_SRC)
17 17
18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua 18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua
19LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua \ 19LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua \
20 image.lua lcd.lua math_ex.lua print.lua timer.lua playlist.lua pcm.lua rbcompat.lua) 20 image.lua lcd.lua math_ex.lua print.lua \
21 timer.lua playlist.lua pcm.lua sound.lua \
22 rbcompat.lua )
21 23
22 24
23ifndef APP_TYPE 25ifndef APP_TYPE
@@ -35,16 +37,13 @@ else
35 ROCKS += $(LUA_BUILDDIR)/lua.rock 37 ROCKS += $(LUA_BUILDDIR)/lua.rock
36endif 38endif
37 39
38$(LUA_BUILDDIR)/lua.rock: $(LUA_OBJ) $(TLSFLIB) $(LUA_BUILDDIR)/actions.lua $(LUA_BUILDDIR)/buttons.lua $(LUA_BUILDDIR)/settings.lua $(LUA_BUILDDIR)/rocklib_aux.o $(LUA_BUILDDIR)/rb_defines.lua $(LUA_INCLUDELIST) 40$(LUA_BUILDDIR)/lua.rock: $(LUA_OBJ) $(TLSFLIB) $(LUA_BUILDDIR)/actions.lua $(LUA_BUILDDIR)/buttons.lua $(LUA_BUILDDIR)/settings.lua \
41 $(LUA_BUILDDIR)/rocklib_aux.o $(LUA_BUILDDIR)/rb_defines.lua $(LUA_BUILDDIR)/sound_defines.lua \
42 $(LUA_INCLUDELIST)
39 43
40$(LUA_BUILDDIR)/actions.lua: $(LUA_OBJ) $(LUA_SRCDIR)/action_helper.pl 44$(LUA_BUILDDIR)/actions.lua: $(LUA_OBJ) $(LUA_SRCDIR)/action_helper.pl
41 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E -P $(APPSDIR)/plugins/lib/pluginlib_actions.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua 45 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E -P $(APPSDIR)/plugins/lib/pluginlib_actions.h | $(LUA_SRCDIR)/action_helper.pl > $(LUA_BUILDDIR)/actions.lua
42 46
43$(LUA_BUILDDIR)/rb_defines.lua: $(LUA_OBJ) $(LUA_SRCDIR)/rbdefines_helper.pl
44 $(SILENT)$(CC) $(INCLUDES) -dD -E -P $(TARGET) $(CFLAGS) -include plugin.h - < /dev/null | $(LUA_SRCDIR)/rbdefines_helper.pl | \
45 $(HOSTCC) -fno-builtin $(HOST_INCLUDES) -x c -o $(LUA_BUILDDIR)/rbdefines_helper -
46 $(call PRINTS,GEN $(@F))$(LUA_BUILDDIR)/rbdefines_helper > $(LUA_BUILDDIR)/rb_defines.lua
47
48$(LUA_BUILDDIR)/settings.lua: $(LUA_OBJ) $(LUA_SRCDIR)/settings_helper.pl 47$(LUA_BUILDDIR)/settings.lua: $(LUA_OBJ) $(LUA_SRCDIR)/settings_helper.pl
49 $(SILENT)$(CC) $(INCLUDES) -E -P $(TARGET) $(CFLAGS) -include plugin.h -include cuesheet.h - < /dev/null | $(LUA_SRCDIR)/settings_helper.pl | \ 48 $(SILENT)$(CC) $(INCLUDES) -E -P $(TARGET) $(CFLAGS) -include plugin.h -include cuesheet.h - < /dev/null | $(LUA_SRCDIR)/settings_helper.pl | \
50 $(CC) $(INCLUDES) $(TARGET) $(CFLAGS) -S -x c -include config.h -include plugin.h -o $(LUA_BUILDDIR)/settings_helper.s - 49 $(CC) $(INCLUDES) $(TARGET) $(CFLAGS) -S -x c -include config.h -include plugin.h -o $(LUA_BUILDDIR)/settings_helper.s -
@@ -55,6 +54,16 @@ $(LUA_BUILDDIR)/buttons.lua: $(LUA_OBJ) $(LUA_SRCDIR)/button_helper.pl
55 $(SILENT)$(CC) $(INCLUDES) -dM -E -P -include button-target.h - < /dev/null | $(LUA_SRCDIR)/button_helper.pl | $(HOSTCC) -fno-builtin $(HOST_INCLUDES) -x c -o $(LUA_BUILDDIR)/button_helper - 54 $(SILENT)$(CC) $(INCLUDES) -dM -E -P -include button-target.h - < /dev/null | $(LUA_SRCDIR)/button_helper.pl | $(HOSTCC) -fno-builtin $(HOST_INCLUDES) -x c -o $(LUA_BUILDDIR)/button_helper -
56 $(call PRINTS,GEN $(@F))$(LUA_BUILDDIR)/button_helper > $(LUA_BUILDDIR)/buttons.lua 55 $(call PRINTS,GEN $(@F))$(LUA_BUILDDIR)/button_helper > $(LUA_BUILDDIR)/buttons.lua
57 56
57$(LUA_BUILDDIR)/rb_defines.lua: $(LUA_OBJ) $(LUA_SRCDIR)/rbdefines_helper.pl
58 $(SILENT)$(CC) $(INCLUDES) -dD -E -P $(TARGET) $(CFLAGS) -include plugin.h - < /dev/null | $(LUA_SRCDIR)/rbdefines_helper.pl "rb_defines" | \
59 $(HOSTCC) -fno-builtin $(HOST_INCLUDES) -x c -o $(LUA_BUILDDIR)/rbdefines_helper -
60 $(call PRINTS,GEN $(@F))$(LUA_BUILDDIR)/rbdefines_helper > $(LUA_BUILDDIR)/rb_defines.lua
61
62$(LUA_BUILDDIR)/sound_defines.lua: $(LUA_OBJ) $(LUA_SRCDIR)/rbdefines_helper.pl
63 $(SILENT)$(CC) $(INCLUDES) -dD -E -P $(TARGET) $(CFLAGS) -include config.h -include audiohw_settings.h - < /dev/null | $(LUA_SRCDIR)/rbdefines_helper.pl "sound_defines" | \
64 $(HOSTCC) -fno-builtin $(HOST_INCLUDES) -x c -o $(LUA_BUILDDIR)/sounddefines_helper -
65 $(call PRINTS,GEN $(@F))$(LUA_BUILDDIR)/sounddefines_helper > $(LUA_BUILDDIR)/sound_defines.lua
66
58$(LUA_BUILDDIR)/rocklib_aux.c: $(APPSDIR)/plugin.h $(LUA_OBJ) $(LUA_SRCDIR)/rocklib_aux.pl 67$(LUA_BUILDDIR)/rocklib_aux.c: $(APPSDIR)/plugin.h $(LUA_OBJ) $(LUA_SRCDIR)/rocklib_aux.pl
59 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E -P -include plugin.h - < /dev/null | $(LUA_SRCDIR)/rocklib_aux.pl $(LUA_SRCDIR) > $(LUA_BUILDDIR)/rocklib_aux.c 68 $(call PRINTS,GEN $(@F))$(CC) $(PLUGINFLAGS) $(INCLUDES) -E -P -include plugin.h - < /dev/null | $(LUA_SRCDIR)/rocklib_aux.pl $(LUA_SRCDIR) > $(LUA_BUILDDIR)/rocklib_aux.c
60 69
diff --git a/apps/plugins/lua/rbdefines_helper.pl b/apps/plugins/lua/rbdefines_helper.pl
index ba15346a8a..b55609077d 100755
--- a/apps/plugins/lua/rbdefines_helper.pl
+++ b/apps/plugins/lua/rbdefines_helper.pl
@@ -20,28 +20,46 @@
20 20
21#rockbox to lua define generator, add names of constants to the array to include 21#rockbox to lua define generator, add names of constants to the array to include
22 22
23my @rockbox_defines = ( 23if ($#ARGV + 1 != 1) {
24 '^HZ$', 24 warn "no definition type defined";
25 '^LCD_(DEPTH|HEIGHT|WIDTH)$', 25 exit;
26 '^MODEL_NAME$', 26}
27 '^SCREEN_MAIN$', 27
28 '^LCD_DEFAULT_(FG|BG)$', 28my $def_type = $ARGV[0];
29 '^LCD_REMOTE_(DEPTH|HEIGHT|WIDTH)$', 29#warn "$def_type\n";
30 '^LCD_.+(BRIGHT|DARK)COLOR', 30my $lua_table;
31 '^SCREEN_REMOTE$', 31my @rockbox_defines;
32 '^FONT_SYSFIXED$', 32
33 '^FONT_UI$', 33if ($def_type eq "rb_defines") {
34 '^PLAYBACK_EVENT_.*', 34 $lua_table = "rb";
35 '^PLAYLIST_(INSERT|PREPEND|REPLACE)', 35 @rockbox_defines = (
36 '^TOUCHSCREEN_(POINT|BUTTON)$', 36 '^HZ$',
37 '^SYS_CHARGER_(DIS|)CONNECTED$', 37 '^LCD_(DEPTH|HEIGHT|WIDTH)$',
38 '^SYS_(TIMEOUT|POWEROFF)$', 38 '^MODEL_NAME$',
39 '^SYS_USB_(DIS|)CONNECTED$', 39 '^SCREEN_MAIN$',
40 '^HOME_DIR$', 40 '^LCD_DEFAULT_(FG|BG)$',
41 '^PLUGIN_DIR$', 41 '^LCD_REMOTE_(DEPTH|HEIGHT|WIDTH)$',
42 '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$', 42 '^LCD_.+(BRIGHT|DARK)COLOR',
43 '^ROCKBOX_DIR$', 43 '^SCREEN_REMOTE$',
44 '^VIEWERS_DATA_DIR$'); 44 '^FONT_SYSFIXED$',
45 '^FONT_UI$',
46 '^PLAYBACK_EVENT_.*',
47 '^PLAYLIST_(INSERT|PREPEND|REPLACE)',
48 '^TOUCHSCREEN_(POINT|BUTTON)$',
49 '^SYS_CHARGER_(DIS|)CONNECTED$',
50 '^SYS_(TIMEOUT|POWEROFF)$',
51 '^SYS_USB_(DIS|)CONNECTED$',
52 '^HOME_DIR$',
53 '^PLUGIN_DIR$',
54 '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$',
55 '^ROCKBOX_DIR$',
56 '^VIEWERS_DATA_DIR$');
57}
58elsif ($def_type eq "sound_defines") {
59 $lua_table = "rb.sound_settings";
60 @rockbox_defines = (
61 '^(?!.*LAST_SETTING)SOUND_');
62}
45 63
46my @captured_defines; 64my @captured_defines;
47my @names_seen; 65my @names_seen;
@@ -115,7 +133,12 @@ while(my $line = <STDIN>)
115 else { next; } 133 else { next; }
116 do_enum($line) 134 do_enum($line)
117 } 135 }
118 136 elsif($line =~ /^enum.*{[^;]+};.*/) #enum {
137 {
138 next if($line =~ /enum\s*__.*/); #don't add reserved
139 next if(do_enum($line));
140
141 }
119} 142}
120#warn "total defines: ".scalar @all_defines; 143#warn "total defines: ".scalar @all_defines;
121#warn "captured defines: ".scalar @captured_defines; 144#warn "captured defines: ".scalar @captured_defines;
@@ -123,17 +146,18 @@ while(my $line = <STDIN>)
123my @sorted_defines = sort { @$a{'name'} cmp @$b{'name'} } @captured_defines; 146my @sorted_defines = sort { @$a{'name'} cmp @$b{'name'} } @captured_defines;
124 147
125printf "int main(void)\n{\n"; 148printf "int main(void)\n{\n";
126printf "\tprintf(\"--[[Autogenerated rockbox constants]]\\n\\n\");"; 149printf "\tprintf(\"--[[Autogenerated rockbox constants]]\\n\\n\");\n\n";
150printf "\tprintf(\"%s = %s or {}\\n\");\n", $lua_table, $lua_table;
127# Print the C array 151# Print the C array
128foreach my $define (@sorted_defines) 152foreach my $define (@sorted_defines)
129{ 153{
130 if(@$define{'value'} =~ /^0[xX][0-9a-fA-F]+$/) #hex number 154 if(@$define{'value'} =~ /^0[xX][0-9a-fA-F]+$/) #hex number
131 { 155 {
132 printf "\tprintf(\"rb[\\\"%%s\\\"] = 0x%%x\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 156 printf "\tprintf(\"%s[\\\"%%s\\\"] = 0x%%x\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
133 } 157 }
134 elsif(@$define{'value'} =~ /^[0-9]+$/) #number 158 elsif(@$define{'value'} =~ /^[0-9]+$/) #number
135 { 159 {
136 printf "\tprintf(\"rb[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 160 printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
137 } 161 }
138 else #might be a string but we don't know since the macro isn't expanded far enough 162 else #might be a string but we don't know since the macro isn't expanded far enough
139 { 163 {
@@ -167,11 +191,11 @@ foreach my $define (@sorted_defines)
167 if ($var =~$quot_regex) #has a quote it is a string 191 if ($var =~$quot_regex) #has a quote it is a string
168 { 192 {
169 #guard with empty literals "" so gcc throws an error if it isn't a string 193 #guard with empty literals "" so gcc throws an error if it isn't a string
170 printf "\tprintf(\"rb[\\\"%%s\\\"] = \\\"%%s\\\"\\n\", stringify(%s), \"\" %s \"\");\n", @$define{'name'}, @$define{'name'}; 194 printf "\tprintf(\"%s[\\\"%%s\\\"] = \\\"%%s\\\"\\n\", stringify(%s), \"\" %s \"\");\n", $lua_table, @$define{'name'}, @$define{'name'};
171 } 195 }
172 elsif ($var =~$num_regex) #it must be a number 196 elsif ($var =~$num_regex) #it must be a number
173 { 197 {
174 printf "\tprintf(\"rb[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 198 printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
175 } 199 }
176 else { warn "Skipping ".@$define{'name'}." indeterminate macro type\n"; } 200 else { warn "Skipping ".@$define{'name'}." indeterminate macro type\n"; }
177 } 201 }
@@ -186,6 +210,23 @@ EOF
186 210
187sub do_enum { 211sub do_enum {
188 my ($line) = @_; 212 my ($line) = @_;
213 if($line =~ /.*enum.*{(.*)};.*/) #single line enums
214 {
215 print $line;
216 $value = "0"; #enums are always integers
217 my $enum = $1;
218 $enum =~ s/\s+//g;;
219 my @values = split(',', $enum);
220
221 foreach my $name(@values) {
222 if(grep($name =~ $_, @rockbox_defines))
223 {
224 push(@names_seen, $name);
225 push(@captured_defines, {'name' => $name, 'value' => $value});
226 }
227 }
228 return 1;
229 }
189 230
190 while($line = <STDIN>) 231 while($line = <STDIN>)
191 { 232 {
@@ -209,4 +250,5 @@ sub do_enum {
209 } 250 }
210 251
211 } 252 }
253 return 0;
212} 254}
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 9518fe955b..b37f5245dc 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -378,6 +378,65 @@ RB_WRAP(audio)
378 return 1; 378 return 1;
379} 379}
380 380
381RB_WRAP(sound)
382{
383 enum e_snd {SOUND_SET = 0, SOUND_CURRENT, SOUND_DEFAULT,
384 SOUND_MIN, SOUND_MAX, SOUND_UNIT, SOUND_SET_PITCH,
385 SOUND_VAL2PHYS, SOUND_ECOUNT};
386
387 const char *snd_option[] = {"set", "current", "default",
388 "min", "max", "unit", "pitch",
389 "val2phys", NULL};
390
391 lua_pushnil(L); /*push nil so options w/o return have something to return */
392
393 int option = luaL_checkoption (L, 1, NULL, snd_option);
394 int setting = luaL_checkint(L, 2);
395 int value, result;
396 switch(option)
397 {
398 case SOUND_SET:
399 value = luaL_checkint(L, 3);
400 rb->sound_set(setting, value);
401 return 1; /*nil*/
402 break;
403 case SOUND_CURRENT:
404 result = rb->sound_current(setting);
405 break;
406 case SOUND_DEFAULT:
407 result = rb->sound_default(setting);
408 break;
409 case SOUND_MIN:
410 result = rb->sound_min(setting);
411 break;
412 case SOUND_MAX:
413 result = rb->sound_max(setting);
414 break;
415 case SOUND_UNIT:
416 lua_pushstring (L, rb->sound_unit(setting));
417 return 1;
418 break;
419#if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
420 (CONFIG_CODEC == SWCODEC)) && defined (HAVE_PITCHCONTROL)
421 case SOUND_SET_PITCH:
422 rb->sound_set_pitch(setting);
423 return 1;/*nil*/
424 break;
425#endif
426 case SOUND_VAL2PHYS:
427 value = luaL_checkint(L, 3);
428 result = rb->sound_val2phys(setting, value);
429 break;
430
431 default:
432 return 1;
433 break;
434 }
435
436 lua_pushinteger(L, result);
437 return 1;
438}
439
381#if CONFIG_CODEC == SWCODEC 440#if CONFIG_CODEC == SWCODEC
382RB_WRAP(pcm) 441RB_WRAP(pcm)
383{ 442{
@@ -723,9 +782,10 @@ static const luaL_Reg rocklib[] =
723 RB_FUNC(gui_syncyesno_run), 782 RB_FUNC(gui_syncyesno_run),
724 RB_FUNC(do_menu), 783 RB_FUNC(do_menu),
725 784
726 /* DEVICE AUDIO / PLAYLIST CONTROL */ 785 /* DEVICE AUDIO / SOUND / PLAYLIST CONTROL */
727 RB_FUNC(audio), 786 RB_FUNC(audio),
728 RB_FUNC(playlist), 787 RB_FUNC(playlist),
788 RB_FUNC(sound),
729#if CONFIG_CODEC == SWCODEC 789#if CONFIG_CODEC == SWCODEC
730 RB_FUNC(pcm), 790 RB_FUNC(pcm),
731 RB_FUNC(mixer_frequency), 791 RB_FUNC(mixer_frequency),
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index 5d77288cc1..c059801b8b 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -99,6 +99,7 @@ my @forbidden_functions = ('^open$',
99 '^pcm_play_(stop|pause|lock|unlock)$', 99 '^pcm_play_(stop|pause|lock|unlock)$',
100 '^pcm_(apply_settings|get_bytes_waiting)$', 100 '^pcm_(apply_settings|get_bytes_waiting)$',
101 '^pcm_(set_frequency|calculate_peaks)$', 101 '^pcm_(set_frequency|calculate_peaks)$',
102 '^sound_(set|current|default|min|max|unit|pitch|val2phys)$',
102 '^mixer_(set|get)_frequency$', 103 '^mixer_(set|get)_frequency$',
103 '^(trigger|cancel)_cpu_boost$', 104 '^(trigger|cancel)_cpu_boost$',
104 '^round_value_to_list32$'); 105 '^round_value_to_list32$');