/* $Id$ */ #include #include #include #include "jack.h" #include "ui.h" int kbhit() { struct timeval tv = { 0L, 0L }; fd_set fds; FD_SET(0, &fds); return select(1, &fds, NULL, NULL, &tv); } int color_map[4]; char status[1024]; UI::UI() { initscr(); noecho(); keypad(stdscr, true); nodelay(stdscr, true); raw(); start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(3, COLOR_BLACK, COLOR_GREEN); for (int i = 0; i < 4; i++) { color_map[i] = COLOR_PAIR(i); } snprintf(status, sizeof status, " "); m_channel = 0; } UI::~UI() { endwin(); } bool UI::Run(Jack &j) { bkgdset(color_map[1]); attrset(color_map[1]); mvprintw(0, 0, " msplit - %s", j.m_client_name); clrtoeol(); mvprintw(3, 0, " %s", status); clrtoeol(); for (int i = 0; i < NUM_CHANNELS; i++) { if (j.IsActive(i)) { bkgdset(color_map[3]); attrset(color_map[3]); } else { bkgdset(color_map[0]); attrset(color_map[0]); } mvprintw(1, 2 + i * 5, "%2d", i + 1); bkgdset(color_map[0]); attrset(color_map[0]); mvprintw(2, 1 + i * 5, "[ ]"); bkgdset(color_map[(m_channel == i) ? 2 : 0]); attrset(color_map[(m_channel == i) ? 2 : 0]); mvprintw(2, 2 + i * 5, "%2d", j.GetChannel(i) + 1); } refresh(); if (!kbhit()) { return false; } int c = getch(); switch (c) { case KEY_LEFT: m_channel = (m_channel + NUM_CHANNELS - 1) % NUM_CHANNELS; break; case KEY_RIGHT: m_channel = (m_channel + 1) % NUM_CHANNELS; break; case KEY_UP: j.IncChannel(m_channel); break; case KEY_DOWN: j.DecChannel(m_channel); break; case UIKEY_QUIT: return true; case UIKEY_RECONNECT: if (!j.Connected()) { if (j.Connect()) { snprintf(status, sizeof status, "Reconnected to JACK"); } } break; case UIKEY_DISCONNECT: if (j.Connected()) { j.Disconnect(); snprintf(status, sizeof status, "Disconnected from JACK"); } break; } return false; }