Updated our source code header to explicitly mention that we are GPL v2 or
[Rockbox.git] / apps / plugins / lib / playback_control.c
blobb82e8bea165cb0d1ec3116f6637201d1f011dd2b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "plugin.h"
23 #include "playback_control.h"
25 const struct plugin_api* api = 0;
26 struct viewport *parentvp = NULL;
28 static bool prevtrack(void)
30 api->audio_prev();
31 return false;
34 static bool play(void)
36 int audio_status = api->audio_status();
37 if (!audio_status && api->global_status->resume_index != -1)
39 if (api->playlist_resume() != -1)
41 api->playlist_start(api->global_status->resume_index,
42 api->global_status->resume_offset);
45 else if (audio_status & AUDIO_STATUS_PAUSE)
46 api->audio_resume();
47 else
48 api->audio_pause();
49 return false;
52 static bool stop(void)
54 api->audio_stop();
55 return false;
58 static bool nexttrack(void)
60 api->audio_next();
61 return false;
64 static bool volume(void)
66 const struct settings_list* vol =
67 api->find_setting(&api->global_settings->volume, NULL);
68 return api->option_screen((struct settings_list*)vol, parentvp, false, "Volume");
71 static bool shuffle(void)
73 const struct settings_list* shuffle =
74 api->find_setting(&api->global_settings->playlist_shuffle, NULL);
75 return api->option_screen((struct settings_list*)shuffle, parentvp, false, "Shuffle");
78 static bool repeat_mode(void)
80 const struct settings_list* repeat =
81 api->find_setting(&api->global_settings->repeat_mode, NULL);
82 int old_repeat = api->global_settings->repeat_mode;
84 api->option_screen((struct settings_list*)repeat, parentvp, false, "Repeat");
86 if (old_repeat != api->global_settings->repeat_mode &&
87 (api->audio_status() & AUDIO_STATUS_PLAY))
88 api->audio_flush_and_reload_tracks();
90 return false;
92 MENUITEM_FUNCTION(prevtrack_item, 0, "Previous Track",
93 prevtrack, NULL, NULL, Icon_NOICON);
94 MENUITEM_FUNCTION(playpause_item, 0, "Pause / Play",
95 play, NULL, NULL, Icon_NOICON);
96 MENUITEM_FUNCTION(stop_item, 0, "Stop Playback",
97 stop, NULL, NULL, Icon_NOICON);
98 MENUITEM_FUNCTION(nexttrack_item, 0, "Next Track",
99 nexttrack, NULL, NULL, Icon_NOICON);
100 MENUITEM_FUNCTION(volume_item, 0, "Change Volume",
101 volume, NULL, NULL, Icon_NOICON);
102 MENUITEM_FUNCTION(shuffle_item, 0, "Enable/Disable Shuffle",
103 shuffle, NULL, NULL, Icon_NOICON);
104 MENUITEM_FUNCTION(repeat_mode_item, 0, "Change Repeat Mode",
105 repeat_mode, NULL, NULL, Icon_NOICON);
106 MAKE_MENU(playback_control_menu, "Playback Control", NULL, Icon_NOICON,
107 &prevtrack_item, &playpause_item, &stop_item, &nexttrack_item,
108 &volume_item, &shuffle_item, &repeat_mode_item);
110 void playback_control_init(const struct plugin_api* newapi,
111 struct viewport parent[NB_SCREENS])
113 api = newapi;
114 parentvp = parent;
117 bool playback_control(const struct plugin_api* newapi,
118 struct viewport parent[NB_SCREENS])
120 api = newapi;
121 parentvp = parent;
122 return api->do_menu(&playback_control_menu, NULL, parent, false) == MENU_ATTACHED_USB;