Browse Source

create basic gtk app

master
Alexandros Theodotou 7 months ago
commit
d421b87da9
Signed by: alex GPG Key ID: 022EAE42313D70F3
  1. 1
      .gitignore
  2. 99
      carla_api_tester.c
  3. 179
      carla_api_tester_app.c
  4. 42
      carla_api_tester_app.h
  5. 100
      meson.build
  6. 5
      meson_options.txt

1
.gitignore

@ -0,0 +1 @@
build

99
carla_api_tester.c

@ -0,0 +1,99 @@
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <carla_api_tester_app.h>
#define PROJECT_NAME "carla-api-tester"
static char * arg0 = NULL;
static char * format = NULL;
static char * plugin = NULL;
static char * bridge = NULL;
int main(int argc, char **argv)
{
arg0 = argv[0];
GOptionEntry entries[] =
{
{ "format", 0, G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &format,
"Plugin format (lv2/vst2/vst3/au)",
"FORMAT" },
{ "plugin", 0, G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &plugin,
"Path to plugin, or URI/identifier",
"PLUGIN" },
{ "bridge", 0, G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &bridge,
"Bridge type (none/ui/full)",
"BRIDGE-TYPE" },
{ NULL },
};
/* parse options */
GError *error = NULL;
char context_str[500];
sprintf (
context_str, "[PROJECT-FILE] - Run %s",
PROJECT_NAME);
GOptionContext * context =
g_option_context_new (context_str);
g_option_context_add_main_entries (
context, entries, NULL);
g_option_context_add_group (
context, gtk_get_option_group (false));
char examples[8000];
sprintf (
examples,
"Examples:\n"
" --plugin=urn:zamaudio:ZamComp --bridge=none --format=lv2\n"
"Please report issues to %s\n",
ISSUE_TRACKER_URL);
g_option_context_set_description (
context, examples);
char * null_terminated_args[argc + 1];
for (int i = 0; i < argc; i++)
{
null_terminated_args[i] = argv[i];
}
null_terminated_args[argc] = NULL;
char ** allocated_args =
g_strdupv (null_terminated_args);
if (!g_option_context_parse_strv (
context, &allocated_args, &error))
{
g_error (
"option parsing failed: %s",
error->message);
}
char * cur_dir = g_get_current_dir ();
g_message (
"Running in %s", cur_dir);
g_free (cur_dir);
g_message ("GTK_THEME=%s", getenv ("GTK_THEME"));
/* init random */
g_message ("Initing random...");
#ifdef _WOE32
srand ((unsigned int) time (NULL));
#else
srandom ((unsigned int) time (NULL));
#endif
carla_api_tester_app =
carla_api_tester_app_new (
plugin, format, bridge);
g_message ("running app...");
int ret =
g_application_run (
G_APPLICATION (carla_api_tester_app), 0, NULL);
g_object_unref (carla_api_tester_app);
return ret;
}

179
carla_api_tester_app.c

@ -0,0 +1,179 @@
#include "config.h"
#include <stdbool.h>
#include <stdlib.h>
#include "carla_api_tester_app.h"
#include <gtk/gtk.h>
/** This is declared extern in zrythm_app.h. */
CarlaApiTesterApp * carla_api_tester_app = NULL;
G_DEFINE_TYPE (
CarlaApiTesterApp, carla_api_tester_app,
GTK_TYPE_APPLICATION);
/*
* Called after startup if no filename is passed on
* command line.
*/
static void
carla_api_tester_app_activate (
GApplication * _app)
{
g_message ("Activating...");
g_message ("done");
}
/**
* Called when a filename is passed to the command line
* instead of activate.
*
* Always gets called after startup and before the tasks.
*/
static void
carla_api_tester_app_open (
GApplication * _app,
GFile ** files,
gint n_files,
const gchar * hint)
{
g_message ("Opening...");
#if 0
g_warn_if_fail (n_files == 1);
GFile * file = files[0];
ZRYTHM->open_filename =
g_file_get_path (file);
g_message ("open %s", ZRYTHM->open_filename);
#endif
g_message ("done");
}
/**
* First function that gets called.
*/
static void
carla_api_tester_app_startup (
GApplication * app)
{
g_message ("Starting up...");
CarlaApiTesterApp * self =
CARLA_API_TESTER_APP (app);
G_APPLICATION_CLASS (
carla_api_tester_app_parent_class)->
startup (G_APPLICATION (self));
g_message (
"called startup on G_APPLICATION_CLASS");
bool ret =
g_application_get_is_registered (
G_APPLICATION (self));
bool remote =
g_application_get_is_remote (
G_APPLICATION (self));
GMenuModel * app_menu_model =
gtk_application_get_app_menu (
GTK_APPLICATION (app));
bool prefers_app_menu =
gtk_application_prefers_app_menu (
GTK_APPLICATION (app));
g_message (
"application registered: %d, is remote %d, "
"app menu exists: %d, prefers app menu: %d",
ret, remote, app_menu_model ? true : false,
prefers_app_menu);
g_message (
"application resources base path: %s",
g_application_get_resource_base_path (
G_APPLICATION (app)));
g_message ("done");
}
/**
* Called immediately after the main GTK loop
* terminates.
*
* This is also called manually on SIGINT.
*/
static void
carla_api_tester_app_on_shutdown (
GApplication * application,
CarlaApiTesterApp * self)
{
g_message ("Shutting down...");
g_message ("done");
}
/**
* Creates the CarlaApiTester GApplication.
*/
CarlaApiTesterApp *
carla_api_tester_app_new (
const char * plugin,
const char * format,
const char * bridge)
{
CarlaApiTesterApp * self = g_object_new (
CARLA_API_TESTER_APP_TYPE,
/* if an ID is provided, this application
* becomes unique (only one instance allowed) */
/*"application-id", "org.carla-api-tester.App",*/
NULL);
carla_api_tester_app = self;
self->bridge = bridge;
self->plugin = plugin;
self->format = format;
/* add shutdown handler */
g_signal_connect (
G_OBJECT (self), "shutdown",
G_CALLBACK (carla_api_tester_app_on_shutdown),
self);
return self;
}
static void
finalize (
CarlaApiTesterApp * self)
{
g_message ("finalizing app...");
g_message ("done");
}
static void
carla_api_tester_app_class_init (
CarlaApiTesterAppClass * class)
{
G_APPLICATION_CLASS (class)->activate =
carla_api_tester_app_activate;
G_APPLICATION_CLASS (class)->startup =
carla_api_tester_app_startup;
G_APPLICATION_CLASS (class)->open =
carla_api_tester_app_open;
GObjectClass * klass = G_OBJECT_CLASS (class);
klass->finalize = (GObjectFinalizeFunc) finalize;
}
static void
carla_api_tester_app_init (
CarlaApiTesterApp * self)
{
g_message ("initing app");
g_message ("done");
}

42
carla_api_tester_app.h

@ -0,0 +1,42 @@
#ifndef __CARLA_API_TESTER_APP_H__
#define __CARLA_API_TESTER_APP_H__
#include <gtk/gtk.h>
#define CARLA_API_TESTER_APP_TYPE \
(carla_api_tester_app_get_type ())
G_DECLARE_FINAL_TYPE (
CarlaApiTesterApp, carla_api_tester_app,
CARLA_API_TESTER, APP, GtkApplication)
/**
* The global struct.
*
* Contains data that is only relevant to the GUI
* and not to CarlaApiTester.
*/
struct _CarlaApiTesterApp
{
GtkApplication parent;
const char * plugin;
const char * format;
const char * bridge;
};
/**
* Global variable, should be available to all files.
*/
extern CarlaApiTesterApp * carla_api_tester_app;
/**
* Creates the CarlaApiTester GApplication.
*/
CarlaApiTesterApp *
carla_api_tester_app_new (
const char * plugin,
const char * format,
const char * bridge);
#endif /* __CARLA_API_TESTER_APP_H__ */

100
meson.build

@ -0,0 +1,100 @@
project('carla-api-tester', 'c',
version : '0.1',
default_options : ['warning_level=3'])
prefix = get_option ('prefix')
bindir = prefix / get_option ('bindir')
libdir = prefix / get_option ('libdir')
os_darwin = false
os_linux = false
os_freebsd = false
os_windows = false
bin_suffix = ''
lib_suffix = '.so'
if host_machine.system() == 'darwin'
os_darwin = true
lib_suffix = '.dylib'
elif host_machine.system() == 'linux'
os_linux = true
elif host_machine.system() == 'freebsd'
os_freebsd = true
elif host_machine.system() == 'windows'
os_windows = true
bin_suffix = '.exe'
lib_suffix = '.dll'
else
error ('unknown host system ' + host_machine.system ())
endif
cdata = configuration_data ()
cdata.set_quoted (
'ISSUE_TRACKER_URL',
'https://todo.sr.ht/~alextee/zrythm-bug')
gtk_dep = dependency (
'gtk+-3.0', version: '>=3.22')
carla_host_plugin_dep = dependency (
'carla-host-plugin', version: '>=2.2.91')
carla_bins_dir = get_option ('carla_binaries_dir')
if carla_bins_dir == ''
carla_bins_dir = carla_host_plugin_dep.get_pkgconfig_variable('libdir')
endif
install_data (
find_program (
carla_bins_dir / 'carla-discovery-native.exe',
carla_bins_dir /
'carla-discovery-native').full_path(),
install_dir: bindir)
# install discovery & bridge for 32-bit vst's on
# windows
if os_windows
install_data (
find_program (
carla_bins_dir /
'carla-discovery-win32.exe').full_path(),
install_dir: bindir)
install_data (
find_program (
carla_bins_dir /
'carla-bridge-win32.exe').full_path(),
install_dir: bindir)
endif
# install gnu/linux bridges
bridge_types = [
'native', 'lv2-gtk2', 'lv2-gtk3', 'lv2-qt4',
'lv2-qt5' ]
foreach bridge_type : bridge_types
carla_bridge = find_program (
carla_bins_dir / 'carla-bridge-' + bridge_type,
required: false)
if carla_bridge.found() and (os_linux or os_freebsd)
cdata.set('HAVE_CARLA_BRIDGE_' + bridge_type.underscorify().to_upper(), 1)
install_data (
carla_bridge.full_path(),
install_dir: bindir)
endif
endforeach
config_h = configure_file (
output: 'config.h',
configuration: cdata,
)
exe = executable (
'carla-api-tester.gtk3',
sources: [
config_h,
'carla_api_tester_app.c',
'carla_api_tester.c',
],
dependencies: [
gtk_dep,
],
install: true)
test ('basic', exe)

5
meson_options.txt

@ -0,0 +1,5 @@
option (
'carla_binaries_dir',
type: 'string',
value: '',
description: 'Location to collect carla discovery and bridge binaries.')
Loading…
Cancel
Save