summaryrefslogtreecommitdiffstats
path: root/src/ganv_bench.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-06 21:01:38 +0000
committerDavid Robillard <d@drobilla.net>2011-12-06 21:01:38 +0000
commit0731f12beaa0cfc0de56dc05ca3814143fd394a5 (patch)
treed8a98ee48badba378172d3a1c46fba2f2e266d37 /src/ganv_bench.cpp
downloadganv-0731f12beaa0cfc0de56dc05ca3814143fd394a5.tar.gz
ganv-0731f12beaa0cfc0de56dc05ca3814143fd394a5.tar.bz2
ganv-0731f12beaa0cfc0de56dc05ca3814143fd394a5.zip
FlowCanvas's successor is hereby dubbed Ganv.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3820 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/ganv_bench.cpp')
-rw-r--r--src/ganv_bench.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/src/ganv_bench.cpp b/src/ganv_bench.cpp
new file mode 100644
index 0000000..693882d
--- /dev/null
+++ b/src/ganv_bench.cpp
@@ -0,0 +1,182 @@
+/* This file is part of Ganv.
+ * Copyright 2011 David Robillard <http://drobilla.net>
+ *
+ * Ganv is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * Ganv is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Ganv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gtkmm/main.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/window.h>
+
+#include "ganv/ganv.hpp"
+
+using namespace std;
+using namespace Ganv;
+
+static const int MAX_NUM_PORTS = 16;
+
+vector<Node*> ins;
+vector<Node*> outs;
+
+Module*
+make_module(Canvas* canvas)
+{
+ char name[8];
+
+ snprintf(name, 8, "mod%d", rand() % 10000);
+ Module* m(new Module(*canvas, name,
+ rand() % (int)canvas->width(),
+ rand() % (int)canvas->height(),
+ true,
+ true));
+
+ int n_ins = rand() % MAX_NUM_PORTS;
+ for (int i = 0; i < n_ins; ++i) {
+ snprintf(name, 8, "in%d", rand() % 10000);
+ Port* p(new Port(*m, name, true,
+ ((rand() % 0xFFFFFF) << 8) | 0xFF));
+ ins.push_back(p);
+ }
+
+ int n_outs = rand() % MAX_NUM_PORTS;
+ for (int i = 0; i < n_outs; ++i) {
+ snprintf(name, 8, "out%d", rand() % 10000);
+ Port* p(new Port(*m, name, false,
+ ((rand() % 0xFFFFFF) << 8) | 0xFF));
+ outs.push_back(p);
+ }
+
+ m->show();
+ return m;
+}
+
+Circle*
+make_circle(Canvas* canvas)
+{
+ char name[8];
+
+ snprintf(name, 8, "%d", rand() % 10000);
+ Circle* e(new Circle(*canvas, name,
+ rand() % (int)canvas->width(),
+ rand() % (int)canvas->height(),
+ 32.0,
+ 32.0));
+
+ ins.push_back(e);
+ outs.push_back(e);
+
+ return e;
+}
+
+bool
+quit()
+{
+ Gtk::Main::quit();
+ return true;
+}
+
+int
+print_usage(const char* name)
+{
+ fprintf(stderr,
+ "USAGE: %s [OPTIONS] CANVAS_W CANVAS_H N_MODULES N_CIRCLES N_EDGES\n\n"
+ "Options:\n"
+ " -o Remain open (do not close immediately)\n"
+ " -a Arrange canvas\n"
+ " -s Straight edges\n",
+ name);
+ return 1;
+}
+
+int
+main(int argc, char** argv)
+{
+ if (argc < 5) {
+ return print_usage(argv[0]);
+ }
+
+ int arg = 1;
+
+ bool remain_open = false;
+ bool arrange = false;
+ bool straight = false;
+ for (; arg < argc && argv[arg][0] == '-'; ++arg) {
+ if (argv[arg][1] == 'o') {
+ remain_open = true;
+ } else if (argv[arg][1] == 'a') {
+ arrange = true;
+ } else if (argv[arg][1] == 's') {
+ straight = true;
+ } else {
+ return print_usage(argv[0]);
+ }
+ }
+
+ const int canvas_w = atoi(argv[arg++]);
+ const int canvas_h = atoi(argv[arg++]);
+
+ if (argc - arg < 3) {
+ return print_usage(argv[0]);
+ }
+
+ const int n_modules = atoi(argv[arg++]);
+ const int n_circles = atoi(argv[arg++]);
+ const int n_edges = atoi(argv[arg++]);
+
+ srand(time(NULL));
+
+ Gtk::Main kit(argc, argv);
+
+ Gtk::Window window;
+ Gtk::ScrolledWindow* scroller = Gtk::manage(new Gtk::ScrolledWindow());
+
+ Canvas* canvas = new Canvas(canvas_w, canvas_h);
+ scroller->add(canvas->widget());
+ window.add(*scroller);
+
+ window.show_all();
+
+ for (int i = 0; i < n_modules; ++i) {
+ make_module(canvas);
+ }
+
+ for (int i = 0; i < n_circles; ++i) {
+ make_circle(canvas);
+ }
+
+ for (int i = 0; i < n_edges; ++i) {
+ Node* src = outs[rand() % outs.size()];
+ Node* dst = ins[rand() % ins.size()];
+ Edge* c = new Edge(*canvas, src, dst, 0x808080FF);
+ if (straight) {
+ c->set_curved(false);
+ }
+ }
+
+ if (arrange) {
+ canvas->arrange();
+ }
+
+ if (!remain_open) {
+ Glib::signal_idle().connect(sigc::ptr_fun(quit));
+ }
+
+ Gtk::Main::run(window);
+
+ return 0;
+}