summaryrefslogtreecommitdiffstats
path: root/apps/sound_menu.c
blob: 256da0b81a7f86fea7da9c047cca5f5ad10badd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 Björn Stenberg
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include "kernel.h"
#include "lcd.h"
#include "menu.h"
#include "button.h"
#include "mp3_playback.h"
#include "settings.h"
#include "status.h"
#include "screens.h"
#ifdef HAVE_LCD_BITMAP
#include "icons.h"
#endif
#include "lang.h"
#include "sprintf.h"

static char *fmt[] =
{
    "",                 /* no decimals */
    "%d.%d %s  ",       /* 1 decimal */
    "%d.%02d %s  "      /* 2 decimals */
};

bool set_sound(char* string, 
               int* variable,
               int setting)
{
    bool done = false;
    bool changed = true;
    int min, max;
    int val;
    int numdec;
    int integer;
    int dec;
    char* unit;
    char str[32];

    unit = mpeg_sound_unit(setting);
    numdec = mpeg_sound_numdecimals(setting);
    min = mpeg_sound_min(setting);
    max = mpeg_sound_max(setting);
    
#ifdef HAVE_LCD_BITMAP
    if(global_settings.statusbar)
        lcd_setmargins(0, STATUSBAR_HEIGHT);
    else
        lcd_setmargins(0, 0);
#endif
    lcd_clear_display();
    lcd_puts_scroll(0,0,string);

    while (!done) {
        if (changed) {
            val = mpeg_val2phys(setting, *variable);
            if(numdec)
            {
                integer = val / (10 * numdec);
                dec = val % (10 * numdec);
                snprintf(str,sizeof str, fmt[numdec], integer, dec, unit);
            }
            else
            {
                snprintf(str,sizeof str,"%d %s  ", val, unit);
            }
        }
        lcd_puts(0,1,str);
        status_draw(true);
        lcd_update();

        changed = false;
        switch( button_get_w_tmo(HZ/2) ) {
#ifdef HAVE_RECORDER_KEYPAD
            case BUTTON_UP:
            case BUTTON_UP | BUTTON_REPEAT:
#else
            case BUTTON_RIGHT:
            case BUTTON_RIGHT | BUTTON_REPEAT:
#endif
                (*variable)++;
                if(*variable > max )
                    *variable = max;
                changed = true;
                break;

#ifdef HAVE_RECORDER_KEYPAD
            case BUTTON_DOWN:
            case BUTTON_DOWN | BUTTON_REPEAT:
#else
            case BUTTON_LEFT:
            case BUTTON_LEFT | BUTTON_REPEAT:
#endif
                (*variable)--;
                if(*variable < min )
                    *variable = min;
                changed = true;
                break;

#ifdef HAVE_RECORDER_KEYPAD
            case BUTTON_LEFT:
#else
            case BUTTON_STOP:
            case BUTTON_MENU:
            case BUTTON_PLAY:
#endif
                done = true;
                break;

            case SYS_USB_CONNECTED:
                usb_screen();
                return true;
        }
        if (changed) {
            mpeg_sound_set(setting, *variable);
#ifdef HAVE_MAS3507D
            if(setting == SOUND_BALANCE)
                mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
#endif
        }
    }
    lcd_stop_scroll();
    return false;
}

static bool volume(void)
{
    return set_sound(str(LANG_VOLUME), &global_settings.volume, SOUND_VOLUME);
}

static bool balance(void)
{
    return set_sound(str(LANG_BALANCE), &global_settings.balance,
                     SOUND_BALANCE);
}

static bool bass(void)
{
    return set_sound(str(LANG_BASS), &global_settings.bass, SOUND_BASS);
};

static bool treble(void)
{
    return set_sound(str(LANG_TREBLE), &global_settings.treble, SOUND_TREBLE);
}

#ifdef HAVE_MAS3587F
static bool loudness(void)
{
    return set_sound(str(LANG_LOUDNESS), &global_settings.loudness, 
                     SOUND_LOUDNESS);
};

static bool bass_boost(void)
{
    return set_sound(str(LANG_BBOOST), &global_settings.bass_boost, 
                     SOUND_SUPERBASS);
};

static void set_avc(int val)
{
    mpeg_sound_set(SOUND_AVC, val);
}

static bool avc(void)
{
    char* names[] = { str(LANG_OFF), "2s", "4s", "8s" };
    return set_option(str(LANG_DECAY), &global_settings.avc, INT,
                      names, 4, set_avc);
}

static bool recsource(void)
{
    char *names[] = {str(LANG_RECORDING_SRC_MIC), str(LANG_RECORDING_SRC_LINE),
                     str(LANG_RECORDING_SRC_DIGITAL) };
    return set_option(str(LANG_RECORDING_SOURCE),
                      &global_settings.rec_source, INT,
                      names, 3, NULL );
}

static bool recfrequency(void)
{
    char *names[] = {"44.1kHz", "48kHz", "32kHz",
                     "22.05kHz", "24kHz", "16kHz"};

    return set_option(str(LANG_RECORDING_FREQUENCY),
                      &global_settings.rec_frequency, INT,
                      names, 6, NULL );
}

static bool recchannels(void)
{
    char *names[] = {str(LANG_CHANNEL_STEREO), str(LANG_CHANNEL_MONO)};

    return set_option(str(LANG_RECORDING_CHANNELS),
                      &global_settings.rec_channels, INT,
                      names, 2, NULL );
}

static bool recquality(void)
{
    return set_int(str(LANG_RECORDING_QUALITY), "",
                   &global_settings.rec_quality, 
                   NULL, 1, 0, 7 );
}

static bool receditable(void)
{
    return set_bool(str(LANG_RECORDING_EDITABLE),
                    &global_settings.rec_editable);
}

static bool rectimesplit(void)
{
    char *names[] = {
        str(LANG_OFF), "00:05","00:10","00:15",
        "00:30","01:00","02:00","04:00",
        "06:00","08:00","10:00","12:00",
        "18:00","24:00"
    };

    return set_option(str(LANG_RECORD_TIMESPLIT),
                      &global_settings.rec_timesplit, INT,
                      names, 14, NULL );
}

static bool recprerecord(void)
{
    char *names[] = {
        str(LANG_OFF),"1s","2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s",
        "10s", "11s", "12s", "13s", "14s", "15s", "16s", "17s", "18s", "19s",
        "20s", "21s", "22s", "23s", "24s", "25s", "26s", "27s", "28s", "29s",
        "30s"
    };

    return set_option(str(LANG_RECORD_PRERECORD_TIME),
                      &global_settings.rec_prerecord_time, INT,
                      names, 31, NULL );
}

static bool recdirectory(void)
{
    char *names[] = {
        rec_base_directory, str(LANG_RECORD_CURRENT_DIR)
    };

    return set_option(str(LANG_RECORD_DIRECTORY),
                      &global_settings.rec_directory, INT,
                      names, 2, NULL );
}

#endif /* HAVE_MAS3587F */

static void set_chanconf(int val)
{
    mpeg_sound_set(SOUND_CHANNELS, val);
}

static bool chanconf(void)
{
    char *names[] = {
        str(LANG_CHANNEL_STEREO),
#ifdef HAVE_LCD_CHARCELLS
        str(LANG_CHANNEL_STEREO_NARROW_PLAYER),
#else
        str(LANG_CHANNEL_STEREO_NARROW_RECORDER),
#endif
        str(LANG_CHANNEL_MONO),
        str(LANG_CHANNEL_LEFT), str(LANG_CHANNEL_RIGHT),
        str(LANG_CHANNEL_KARAOKE), str(LANG_CHANNEL_STEREO_WIDE)
    };
    return set_option(str(LANG_CHANNEL), &global_settings.channel_config, INT,
                      names, 7, set_chanconf );
}

bool sound_menu(void)
{
    int m;
    bool result;
    struct menu_items items[] = {
        { str(LANG_VOLUME), volume },
        { str(LANG_BASS), bass },
        { str(LANG_TREBLE), treble },
        { str(LANG_BALANCE), balance },
        { str(LANG_CHANNEL_MENU), chanconf },
#ifdef HAVE_MAS3587F
        { str(LANG_LOUDNESS), loudness },
        { str(LANG_BBOOST), bass_boost },
        { str(LANG_AUTOVOL), avc }
#endif
    };
    
    m=menu_init( items, sizeof items / sizeof(struct menu_items), NULL );
    result = menu_run(m);
    menu_exit(m);

    return result;
}

#ifdef HAVE_MAS3587F
bool recording_menu(bool no_source)
{
    int m;
    int i = 0;
    struct menu_items menu[8];
    bool result;

    menu[i].desc = str(LANG_RECORDING_QUALITY);
    menu[i++].function = recquality;
    menu[i].desc = str(LANG_RECORDING_FREQUENCY);
    menu[i++].function = recfrequency;
    if(!no_source) {
        menu[i].desc = str(LANG_RECORDING_SOURCE);
        menu[i++].function = recsource;
    }
    menu[i].desc = str(LANG_RECORDING_CHANNELS);
    menu[i++].function = recchannels;
    menu[i].desc = str(LANG_RECORDING_EDITABLE);
    menu[i++].function = receditable;
    menu[i].desc = str(LANG_RECORD_TIMESPLIT);
    menu[i++].function = rectimesplit;
    menu[i].desc = str(LANG_RECORD_PRERECORD_TIME);
    menu[i++].function = recprerecord;
    menu[i].desc = str(LANG_RECORD_DIRECTORY);
    menu[i++].function = recdirectory;
        
    m=menu_init( menu, i, NULL );
    result = menu_run(m);
    menu_exit(m);

    return result;
}
#endif