1 /*
2  * Copyright (C) 2010-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __ardour_gtk_midi_tracer_h__
23 #define __ardour_gtk_midi_tracer_h__
24 
25 #include <gtkmm/textview.h>
26 #include <gtkmm/scrolledwindow.h>
27 #include <gtkmm/togglebutton.h>
28 #include <gtkmm/adjustment.h>
29 #include <gtkmm/spinbutton.h>
30 #include <gtkmm/label.h>
31 #include <gtkmm/comboboxtext.h>
32 #include <gtkmm/box.h>
33 
34 #include "pbd/signals.h"
35 #include "pbd/ringbuffer.h"
36 #include "pbd/pool.h"
37 #include "pbd/g_atomic_compat.h"
38 
39 #include "midi++/types.h"
40 #include "ardour_window.h"
41 
42 namespace MIDI {
43 	class Parser;
44 }
45 
46 namespace ARDOUR {
47 	class MidiPort;
48 }
49 
50 class MidiTracer : public ArdourWindow
51 {
52 public:
53 	MidiTracer ();
54 	~MidiTracer();
55 
56 private:
57 	Gtk::TextView text;
58 	Gtk::ScrolledWindow scroller;
59 	Gtk::Adjustment line_count_adjustment;
60 	Gtk::SpinButton line_count_spinner;
61 	Gtk::Label line_count_label;
62 	Gtk::HBox line_count_box;
63 	MIDI::samplecnt_t _last_receipt;
64 
65 	bool autoscroll;
66 	bool show_hex;
67 	bool show_delta_time;
68 
69 	/** Incremented when an update is requested, decremented when one is handled; hence
70 	 *  equal to 0 when an update is not queued.  May temporarily be negative if a
71 	 *  update is handled before it was noted that it had just been queued.
72 	 */
73 	GATOMIC_QUAL gint _update_queued;
74 
75 	PBD::RingBuffer<char *> fifo;
76 	Pool buffer_pool;
77 	static const size_t buffer_size = 256;
78 
79 	void tracer (MIDI::Parser&, MIDI::byte*, size_t, MIDI::samplecnt_t);
80 	void update ();
81 
82 	Gtk::CheckButton autoscroll_button;
83 	Gtk::CheckButton base_button;
84 	Gtk::CheckButton collect_button;
85 	Gtk::CheckButton delta_time_button;
86 	Gtk::ComboBoxText _port_combo;
87 
88 	void base_toggle ();
89 	void autoscroll_toggle ();
90 	void collect_toggle ();
91 	void delta_toggle ();
92 
93 	void port_changed ();
94 	void ports_changed ();
95 	void disconnect ();
96 	PBD::ScopedConnection _parser_connection;
97 	PBD::ScopedConnection _manager_connection;
98 	MIDI::Parser my_parser;
99 
100 	boost::shared_ptr<ARDOUR::Port>	tracer_port;
101 	boost::shared_ptr<ARDOUR::MidiPort> traced_port;
102 
103 	static unsigned int window_count;
104 };
105 
106 #endif /* __ardour_gtk_midi_tracer_h__ */
107