Fix race causing MIDI tracer to stop working when master record state is changed.
[ardour.git] / gtk2_ardour / midi_tracer.h
1 #ifndef __ardour_gtk_midi_tracer_h__
2 #define __ardour_gtk_midi_tracer_h__
3
4 #include <gtkmm/textview.h>
5 #include <gtkmm/scrolledwindow.h>
6 #include <gtkmm/togglebutton.h>
7 #include <gtkmm/adjustment.h>
8 #include <gtkmm/spinbutton.h>
9 #include <gtkmm/label.h>
10
11 #include "pbd/signals.h"
12 #include "pbd/ringbuffer.h"
13 #include "pbd/pool.h"
14 #include "midi++/types.h"
15 #include "ardour_dialog.h"
16
17 namespace MIDI {
18         class Parser;
19 }
20
21 class MidiTracer : public ArdourDialog
22 {
23   public:
24         MidiTracer (const std::string&, MIDI::Parser&);
25         ~MidiTracer();
26
27   private:
28         MIDI::Parser& parser;
29         Gtk::TextView text;
30         Gtk::ScrolledWindow scroller;
31         Gtk::Adjustment line_count_adjustment;
32         Gtk::SpinButton line_count_spinner;
33         Gtk::Label line_count_label;
34         Gtk::HBox line_count_box;
35
36         bool autoscroll;
37         bool show_hex;
38         bool collect;
39         
40         /** Incremented when an update is requested, decremented when one is handled; hence
41          *  equal to 0 when an update is not queued.  May temporarily be negative if a
42          *  update is handled before it was noted that it had just been queued.
43          */
44         volatile gint _update_queued;
45          
46         RingBuffer<char *> fifo;
47         Pool buffer_pool;
48         static const size_t buffer_size = 256;
49
50         void tracer (MIDI::Parser&, MIDI::byte*, size_t);
51         void update ();
52         
53         Gtk::CheckButton autoscroll_button;
54         Gtk::CheckButton base_button;
55         Gtk::CheckButton collect_button;
56
57         void base_toggle ();
58         void autoscroll_toggle ();
59         void collect_toggle ();
60
61         void connect ();
62         void disconnect ();
63         PBD::ScopedConnection connection;
64 };
65
66 #endif /* __ardour_gtk_midi_tracer_h__ */