A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 242 lines 7.3 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2002 Gilles Roux 11 * 2003 Garrett Derner 12 * 2010 Yoshihisa Uchida 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 2 17 * of the License, or (at your option) any later version. 18 * 19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 * KIND, either express or implied. 21 * 22 ****************************************************************************/ 23#include "plugin.h" 24#include "lib/pluginlib_exit.h" 25#include "tv_action.h" 26#include "tv_button.h" 27#include "tv_preferences.h" 28 29 30 31enum plugin_status plugin_start(const void* file) 32{ 33 int button; 34#if defined(TV_AUTOSCROLL_PRE) 35 int lastbutton = BUTTON_NONE; 36#endif 37 bool autoscroll = false; 38 long old_tick; 39 bool done = false; 40 bool display_update = true; 41 size_t size; 42 unsigned char *plugin_buf; 43 44 old_tick = *rb->current_tick; 45 46 if (!file) 47 return PLUGIN_ERROR; 48 49 /* get the plugin buffer */ 50 plugin_buf = rb->plugin_get_buffer(&size); 51 52 if (!tv_init_action(&plugin_buf, &size)) { 53 rb->splashf(HZ, ID2P(LANG_ERROR_FORMATSTR), "initialize"); 54 return PLUGIN_ERROR; 55 } 56 57 /* Voice that we're loading the file... */ 58 if (rb->global_settings->talk_menu) { 59 rb->talk_id(LANG_WAIT, true); 60 rb->talk_file_or_spell(NULL, file, NULL, true); 61 rb->talk_force_enqueue_next(); 62 } 63// rb->splashf(HZ/2, "%s %s", rb->str(LANG_WAIT), file); 64 65 if (!tv_load_file(file)) { 66 rb->splashf(HZ, ID2P(LANG_ERROR_FORMATSTR), "reading file"); 67 return PLUGIN_ERROR; 68 } 69 70 atexit(tv_exit); 71 while (!done) { 72 if (preferences->statusbar) 73 rb->send_event(GUI_EVENT_ACTIONUPDATE, NULL); 74 75 if (display_update) 76 tv_draw(); 77 78 display_update = true; 79 80 button = rb->button_get_w_tmo(HZ/10); 81 82 switch (button) { 83 case TV_MENU: 84#ifdef TV_MENU2 85 case TV_MENU2: 86#endif 87 { 88 unsigned res = tv_menu(); 89 90 if (res != TV_MENU_RESULT_EXIT_MENU) 91 { 92 if (res == TV_MENU_RESULT_ATTACHED_USB) 93 return PLUGIN_USB_CONNECTED; 94 else if (res == TV_MENU_RESULT_ERROR) 95 return PLUGIN_ERROR; 96 else 97 done = true; 98 } 99 } 100 break; 101 102 case TV_AUTOSCROLL: 103#ifdef TV_AUTOSCROLL_PRE 104 if (lastbutton != TV_AUTOSCROLL_PRE) 105 break; 106#endif 107#ifdef TV_AUTOSCROLL2 108 /* fallthrough */ 109 case TV_AUTOSCROLL2: 110#endif 111 autoscroll = !autoscroll; 112 break; 113 114 case TV_SCROLL_UP: 115 case TV_SCROLL_UP | BUTTON_REPEAT: 116#ifdef TV_SCROLL_UP2 117 case TV_SCROLL_UP2: 118 case TV_SCROLL_UP2 | BUTTON_REPEAT: 119#endif 120 tv_scroll_up(TV_VERTICAL_SCROLL_PREFS); 121 old_tick = *rb->current_tick; 122 break; 123 124 case TV_SCROLL_DOWN: 125 case TV_SCROLL_DOWN | BUTTON_REPEAT: 126#ifdef TV_PAGE_DOWN2 127 case TV_SCROLL_DOWN2: 128 case TV_SCROLL_DOWN2 | BUTTON_REPEAT: 129#endif 130 tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); 131 old_tick = *rb->current_tick; 132 break; 133 134 case TV_SCREEN_LEFT: 135 case TV_SCREEN_LEFT | BUTTON_REPEAT: 136 if (preferences->windows > 1) 137 { 138 /* Screen left */ 139 tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS); 140 } 141 else { /* prefs->windows == 1 */ 142 if (preferences->narrow_mode == NM_PAGE) 143 { 144 /* scroll to previous page */ 145 tv_scroll_up(TV_VERTICAL_SCROLL_PAGE); 146 } 147 else 148 { 149 /* Top of file */ 150 tv_top(); 151 } 152 } 153 break; 154 155 case TV_SCREEN_RIGHT: 156 case TV_SCREEN_RIGHT | BUTTON_REPEAT: 157 if (preferences->windows > 1) 158 { 159 /* Screen right */ 160 tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS); 161 } 162 else { /* prefs->windows == 1 */ 163 if (preferences->narrow_mode == NM_PAGE) 164 { 165 /* scroll to next page */ 166 tv_scroll_down(TV_VERTICAL_SCROLL_PAGE); 167 } 168 else 169 { 170 /* Bottom of file */ 171 tv_bottom(); 172 } 173 } 174 break; 175 176#ifdef TV_LINE_UP 177 case TV_LINE_UP: 178 case TV_LINE_UP | BUTTON_REPEAT: 179 /* Scroll up one line */ 180 tv_scroll_up(TV_VERTICAL_SCROLL_LINE); 181 old_tick = *rb->current_tick; 182 break; 183 184 case TV_LINE_DOWN: 185 case TV_LINE_DOWN | BUTTON_REPEAT: 186 /* Scroll down one line */ 187 tv_scroll_down(TV_VERTICAL_SCROLL_LINE); 188 old_tick = *rb->current_tick; 189 break; 190#endif 191#ifdef TV_COLUMN_LEFT 192 case TV_COLUMN_LEFT: 193 case TV_COLUMN_LEFT | BUTTON_REPEAT: 194 /* Scroll left one column */ 195 tv_scroll_left(TV_HORIZONTAL_SCROLL_COLUMN); 196 break; 197 198 case TV_COLUMN_RIGHT: 199 case TV_COLUMN_RIGHT | BUTTON_REPEAT: 200 /* Scroll right one column */ 201 tv_scroll_right(TV_HORIZONTAL_SCROLL_COLUMN); 202 break; 203#endif 204 205#ifdef TV_RC_QUIT 206 case TV_RC_QUIT: 207#endif 208 case TV_QUIT: 209#ifdef TV_QUIT2 210 case TV_QUIT2: 211#endif 212 done = true; 213 break; 214 215 case TV_BOOKMARK: 216 tv_add_or_remove_bookmark(); 217 break; 218 219 default: 220 exit_on_usb(button); 221 display_update = false; 222 break; 223 } 224 if (button != BUTTON_NONE) 225 { 226#if defined(TV_AUTOSCROLL_PRE) 227 lastbutton = button; 228#endif 229 rb->yield(); 230 } 231 if (autoscroll) 232 { 233 if(old_tick <= *rb->current_tick - (110 - preferences->autoscroll_speed * 10)) 234 { 235 tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); 236 old_tick = *rb->current_tick; 237 display_update = true; 238 } 239 } 240 } 241 return PLUGIN_OK; 242}