78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
extern "C" {
|
|
#include <core/audio.h>
|
|
#include <core/tempq.h>
|
|
#include <core/version.h>
|
|
#include <gui/builder.h>
|
|
}
|
|
#include <gui/ocarina.h>
|
|
#include <gui/tabs.h>
|
|
|
|
const std::string appname = "Ocarina ";
|
|
|
|
static bool on_window_key_pressed(GdkEventKey *event)
|
|
{
|
|
Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false);
|
|
Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false);
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
|
|
if (key.size() >= 3) {
|
|
if (key.substr(0, 3) == "KP_")
|
|
key = key.substr(3);
|
|
}
|
|
|
|
if (key == "Escape")
|
|
window->set_focus(*window);
|
|
else if (key == "slash")
|
|
tab_focus_search();
|
|
else if (key >= "0" && key <= "9") {
|
|
unsigned int n = atoi(key.c_str());
|
|
if (n < tempq_count())
|
|
notebook->set_current_page(n);
|
|
} else if (key == "c")
|
|
notebook->set_current_page(tempq_count());
|
|
else if (key == "h")
|
|
notebook->set_current_page(tempq_count() + 1);
|
|
else if (key == "m")
|
|
notebook->set_current_page(tempq_count() + 3);
|
|
else if (key == "n")
|
|
audio_next();
|
|
else if (key == "N")
|
|
audio_prev();
|
|
else if (key == "p")
|
|
notebook->set_current_page(tempq_count() + 2);
|
|
else
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
static bool on_window_key_released(GdkEventKey *event)
|
|
{
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
|
|
if (key != "space")
|
|
return false;
|
|
|
|
if (audio_cur_state() == GST_STATE_PLAYING)
|
|
audio_pause();
|
|
else
|
|
audio_play();
|
|
return true;
|
|
}
|
|
|
|
Gtk::Window *window_init()
|
|
{
|
|
Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false);
|
|
|
|
window->set_can_focus();
|
|
window->set_title(appname + get_version());
|
|
window->set_icon_from_file(gui :: share_file("ocarina.png"));
|
|
|
|
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
|
|
window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released));
|
|
|
|
return window;
|
|
}
|