Guitarix
gx_main_midi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * ---------------------------------------------------------------------------
19  *
20  * This file is part of the guitarix GUI main class
21  * Note: this header file depends on gx_parameter.h
22  * and make use of the gx_engine namespace
23  *
24  * ----------------------------------------------------------------------------
25  */
26 
27 #pragma once
28 
29 #ifndef SRC_HEADERS_GX_MAIN_MIDI_H_
30 #define SRC_HEADERS_GX_MAIN_MIDI_H_
31 
32 #ifndef SRC_HEADERS_GX_PARAMETER_H_
33 #include "./gx_parameter.h"
34 #endif
35 
36 #include <glibmm.h>
37 #include <gtk/gtk.h>
38 
39 #include <iomanip>
40 #include <cstring>
41 #include <string>
42 
43 namespace gx_main_midi {
44 /****************************************************************
45  ** MidiControllerTable
46  */
47 
48 class MidiControllerTable: public sigc::trackable {
49  private:
50  enum {RESPONSE_DELETE_SELECTED};
51  static GtkWidget *window; // there can only be 1 window
52  GtkToggleButton *togglebutton;
53  GtkTreeSelection *selection;
54  GtkListStore *store;
55  Glib::RefPtr<Gtk::ToggleAction> menuaction;
56  gx_engine::GxMachineBase& machine;
57  sigc::connection midi_conn;
58  static void response_cb(GtkWidget *widget, gint response_id, gpointer data);
59  static void edited_cb(GtkCellRendererText *renderer, gchar *path,
60  gchar *new_text, gpointer data);
61  static void destroy_cb(GtkWidget*, gpointer data);
62  static void toggleButtonSetSwitch(GtkWidget *w, gpointer data);
63  void set(bool v);
64  void load();
65  explicit MidiControllerTable(gx_engine::GxMachineBase& machine, Glib::RefPtr<Gtk::ToggleAction> item);
67  public:
68  static void toggle(gx_engine::GxMachineBase& machine, Glib::RefPtr<Gtk::ToggleAction> item);
69 };
70 
71 /*****************************************************************
72  ** Midi Control
73  */
74 
75 class MidiConnect {
76  private:
77  enum { RESPONSE_DELETE = 1 };
78  std::map<gx_engine::Parameter::toggle_type, const char*> toggle_behaviour_descriptions {
79  { gx_engine::Parameter::toggle_type::OnOff, "off /on states transition toggle" },
80  { gx_engine::Parameter::toggle_type::Constant, "constant state toggle" }
81  };
82  GtkTreeSelection* selection;
83  GtkListStore* store;
84  gx_engine::Parameter &param;
85  gx_engine::GxMachineBase& machine;
86  int current_control;
87  GtkAdjustment* adj_lower;
88  GtkAdjustment* adj_upper;
89  GtkToggleButton *use_toggle;
90  //
91  GtkWidget* dialog;
92  GtkWidget* entry_new;
93  GtkWidget* label_desc;
94  GtkWidget* toggle_behaviours;
95  static string ctr_desc(int ctr);
96  static const char *ctl_to_str(int n);
97  public:
98  MidiConnect(GdkEventButton *event, gx_engine::Parameter& param, gx_engine::GxMachineBase& machine);
99  static void midi_response_cb(GtkWidget *widget, gint response_id, gpointer data);
100  static void midi_destroy_cb(GtkWidget *widget, gpointer data);
101  static void toggle_behaviours_visibility(GtkWidget *widget, gpointer data);
102  static gboolean check_midi_cb(gpointer);
103  static void changed_text_handler(GtkEditable *entry, gpointer data);
104 };
105 
106 } // end namespace
107 #endif // SRC_HEADERS_GX_MAIN_MIDI_H_
108 
static void toggle(gx_engine::GxMachineBase &machine, Glib::RefPtr< Gtk::ToggleAction > item)