aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2023-11-17 20:30:39 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2023-11-17 20:30:39 +0100
commit68a4257f117fd55287e589a62168cb9d35a362d9 (patch)
treeb2cd9d9b2ef44ca133623435cb34c746fef37770
parent00e6a8a5a32222d65df85005dc404988f9430bc7 (diff)
Refresh button
-rw-r--r--README.md12
-rw-r--r--src/main.c64
2 files changed, 53 insertions, 23 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e3da8d7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,12 @@
+# Directional Audio Visualizer (For Deaf People)
+The main goal of this project is to help people with SSD (single sided deafness) have stereo.
+
+### Dependancies:
+- portaudio
+- gtk4
+
+#### Arch Linux:
+```sh
+pacman -S portaudio gtk4
+make run
+```
diff --git a/src/main.c b/src/main.c
index e5b7988..f5db2de 100644
--- a/src/main.c
+++ b/src/main.c
@@ -82,11 +82,47 @@ static void draw(cairo_t *cr, GtkWidget *area)
static void draw_cb(GtkDrawingArea *drawing_area, cairo_t *cr, int width, int height, gpointer data)
{
cairo_paint(cr);
- draw(cr, data);
+ draw(cr, (GtkWidget*)data);
}
-static void refresh()
+static void refresh(GtkWidget* grid)
{
+ Pa_Terminate();
+ Pa_Initialize();
+ GtkWidget *button;
+ int numDevices = Pa_GetDeviceCount();
+
+ if (numDevices < 0) {
+ printf("Error getting device count.\n");
+ exit(EXIT_FAILURE);
+ } else if (numDevices == 0) {
+ printf("There are no available audio devices on this machine.\n");
+ exit(EXIT_SUCCESS);
+ }
+
+ for (int i = 0; i < numDevices; i++) {
+ const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i);
+ struct data *d = (struct data*)malloc(sizeof(struct data));
+ d->device_num = i;
+ button = gtk_button_new_with_label(deviceInfo->name);
+ g_signal_connect(button, "clicked", G_CALLBACK(select_device), d);
+ gtk_grid_attach(GTK_GRID(grid), button, 0, numDevices - i - 1, 1, 1);
+ }
+
+ gtk_widget_queue_draw(grid);
+}
+
+static void close_window(GtkWindow* window)
+{
+ if (stream != NULL) {
+ Pa_StopStream(stream);
+ Pa_CloseStream(stream);
+ stream = NULL;
+ }
+
+ Pa_Terminate();
+
+ gtk_window_destroy(window);
}
static void activate(GtkApplication *app, gpointer user_data)
@@ -111,34 +147,16 @@ static void activate(GtkApplication *app, gpointer user_data)
// init audio devices
Pa_Initialize();
- int numDevices = Pa_GetDeviceCount();
-
- if (numDevices < 0) {
- printf("Error getting device count.\n");
- exit(EXIT_FAILURE);
- } else if (numDevices == 0) {
- printf("There are no available audio devices on this machine.\n");
- exit(EXIT_SUCCESS);
- }
-
- // init button for every audio device
- for (int i = 0; i < numDevices; i++) {
- const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(i);
- struct data *d = malloc(sizeof(struct data));
- d->device_num = i;
- button = gtk_button_new_with_label(deviceInfo->name);
- g_signal_connect(button, "clicked", G_CALLBACK(select_device), d);
- gtk_grid_attach(GTK_GRID(grid), button, 0, numDevices - i - 1, 1, 1);
- }
+ refresh(grid);
// init button for refresh
button = gtk_button_new_with_label("Refresh");
- g_signal_connect_swapped(button, "clicked", G_CALLBACK(refresh), window);
+ g_signal_connect_swapped(button, "clicked", G_CALLBACK(refresh), grid);
gtk_grid_attach(GTK_GRID(grid), button, 1, 0, 1, 1);
// init button for quit
button = gtk_button_new_with_label("Quit");
- g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_destroy), window);
+ g_signal_connect_swapped(button, "clicked", G_CALLBACK(close_window), window);
gtk_grid_attach(GTK_GRID(grid), button, 1, 1, 1, 1);
// set window