#include #include "config.h" #include "library.h" #include "luigi.h" #include "memory.h" Library lib; Player pl; UIButton* play_button; UISlider* seek_slider; UIImageDisplay* cover_image; UILabel* title_text; UILabel* album_text; UILabel* artist_text; void ui_update_play(void) { UI_FREE(play_button->label); play_button->label = UIStringCopy( pl.play? "Pause": "Play", -1 ); UIImageDisplaySetContent( cover_image, pl.cover, album_cover_w, album_cover_h, album_cover_w * 4 ); UILabelSetContent( title_text, pl.song->name, -1 ); UILabelSetContent( album_text, pl.song->album, -1 ); UILabelSetContent( artist_text, pl.song->artist, -1 ); UIElementRefresh(cover_image->e.parent); } void ui_update_seek(void) { float p; if (!pl.song) return; p = (float)pl.cs / (float)pl.ms; seek_slider->position = p; UIElementRefresh((UIElement*)seek_slider); } int libtab_msg( UIElement* el, UIMessage msg, int di, void* dp ) { Song* song; (void)di; (void)dp; if (msg == UI_MSG_TABLE_GET_ITEM) { UITableGetItem *m = (UITableGetItem*)dp; song = &lib.songs[lib.indices[m->index]]; m->isSelected = 0; switch (m->column) { case 0: return snprintf( m->buffer, m->bufferBytes, "%s", song->name ); case 1: return snprintf( m->buffer, m->bufferBytes, "%s", song->artist ); case 2: return snprintf( m->buffer, m->bufferBytes, "%s", song->album ); case 3: return snprintf( m->buffer, m->bufferBytes, "%s", song->path ); default: return 0; } } else if (msg == UI_MSG_LEFT_UP) { int hit = UITableHitTest( (UITable*)el, el->window->cursorX, el->window->cursorY ); song = &lib.songs[lib.indices[hit]]; play_song(&pl, song); ui_update_play(); } return 0; } int playpause_msg( UIElement* el, UIMessage msg, int di, void* dp ) { (void)el; (void)di; (void)dp; if (msg == UI_MSG_CLICKED) { if (!pl.song) return 0; pl.play = !pl.play; ui_update_play(); } return 0; } int start_msg( UIElement* el, UIMessage msg, int di, void* dp ) { (void)el; (void)di; (void)dp; if (msg == UI_MSG_CLICKED) { if (!pl.song) return 0; play_seek(&pl, 0.0f); } return 0; } int end_msg( UIElement* el, UIMessage msg, int di, void* dp ) { (void)el; (void)di; (void)dp; if (msg == UI_MSG_CLICKED) { if (!pl.song) return 0; play_seek(&pl, 1.0f); } return 0; } int seek_msg( UIElement* el, UIMessage msg, int di, void* dp ) { UISlider* sl; (void)el; (void)di; (void)dp; if (msg == UI_MSG_VALUE_CHANGED) { sl = (UISlider*)el; play_seek(&pl, sl->position); } else if (msg == UI_MSG_ANIMATE) { ui_update_seek(); } return 0; } int prog_main(void* mem) { Arena liba; UIWindow* wi; UISplitPane* split1, * split2, * split3; UIPanel* plib, * pctrl, * plist, * pqueue; UITable* libtab; int r; memory_init(mem); init_arena( &liba, galloc(library_memory_size), library_memory_size ); build_library(&liba, &lib, library_path); init_player(&pl); UIInitialise(); wi = UIWindowCreate( 0, 0, app_name, default_window_w, default_window_h ); split1 = UISplitPaneCreate( &wi->e, 0, 0.3f ); split3 = UISplitPaneCreate( &split1->e, UI_SPLIT_PANE_VERTICAL, 0.5f ); split2 = UISplitPaneCreate( &split1->e, 0, 0.5f ); pctrl = UIPanelCreate(&split3->e, UI_PANEL_GRAY); pctrl->gap = 5; pctrl->border = UI_RECT_1(5); title_text = UILabelCreate( &pctrl->e, 0, "", -1 ); album_text = UILabelCreate( &pctrl->e, 0, "", -1 ); artist_text = UILabelCreate( &pctrl->e, 0, "", -1 ); cover_image = UIImageDisplayCreate( &pctrl->e, 0, (unsigned*)pl.cover, album_cover_w, album_cover_h, album_cover_w ); play_button = UIButtonCreate( &pctrl->e, 0, "Play", -1 ); play_button->e.messageUser = playpause_msg; UIButtonCreate( &pctrl->e, 0, "Start", -1 )->e.messageUser = start_msg; UIButtonCreate( &pctrl->e, 0, "End", -1 )->e.messageUser = end_msg; seek_slider = UISliderCreate( &pctrl->e, UI_ELEMENT_H_FILL ); seek_slider->e.messageUser = seek_msg; pqueue = UIPanelCreate(&split3->e, UI_PANEL_GRAY); pqueue->gap = 5; pqueue->border = UI_RECT_1(5); UILabelCreate( &pqueue->e, 0, "Queue", 5 ); plist = UIPanelCreate(&split2->e, UI_PANEL_GRAY); plist->gap = 5; plist->border = UI_RECT_1(5); UILabelCreate( &plist->e, 0, "Playlist", 8 ); plib = UIPanelCreate(&split2->e, UI_PANEL_GRAY); plib->gap = 5; plib->border = UI_RECT_1(5); UILabelCreate( &plib->e, 0, "Library", 7 ); libtab = UITableCreate( &plib->e, UI_ELEMENT_H_FILL | UI_ELEMENT_V_FILL, "Track\tArtist\tAlbum\tFilename" ); libtab->itemCount = lib.cnt; libtab->e.messageUser = libtab_msg; UITableResizeColumns(libtab); r = UIMessageLoop(); deinit_player(&pl); return r; }