handle async communication from xjadeo
authorRobin Gareus <robin@gareus.org>
Sun, 9 Jun 2013 20:56:03 +0000 (22:56 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 9 Jun 2013 20:56:34 +0000 (22:56 +0200)
gtk2_ardour/video_monitor.cc
gtk2_ardour/video_monitor.h

index f0240b79be09a52acd63219cd77f7cfed745da94..94c88b1180b7d4be7c46d513b7369f534836d26b 100644 (file)
@@ -48,6 +48,7 @@ VideoMonitor::VideoMonitor (PublicEditor *ed, std::string xjadeo_bin_path)
        process = new SystemExec(xjadeo_bin_path, X_("-R"));
        process->ReadStdout.connect_same_thread (*this, boost::bind (&VideoMonitor::parse_output, this, _1 ,_2));
        process->Terminated.connect (*this, invalidator (*this), boost::bind (&VideoMonitor::terminated, this), gui_context());
+       XJKeyEvent.connect (*this, invalidator (*this), boost::bind (&VideoMonitor::forward_keyevent, this, _1), gui_context());
 }
 
 VideoMonitor::~VideoMonitor ()
@@ -131,7 +132,18 @@ VideoMonitor::open (std::string filename)
        process->write_to_stdin("window resize 100%\n");
        process->write_to_stdin("window ontop on\n");
        process->write_to_stdin("set seekmode 1\n");
-       process->write_to_stdin("set override 47\n");
+       /* override bitwise flags -- see xjadeo.h
+        * 0x01 : ignore 'q', ESC  / quite
+        * 0x02 : ignore "window closed by WM" / quit
+        * 0x04 : (osx only) menu-exit / quit
+        * 0x08 : ignore mouse-button 1 -- resize
+        * 0x10 : no A/V offset
+        * 0x20 : don't use jack-session
+        * 0x40 : no jack-transport control play/pause/rewind
+        */
+       process->write_to_stdin("set override 104\n");
+       process->write_to_stdin("notify keyboard\n");
+       process->write_to_stdin("notify settings\n");
        process->write_to_stdin("window letterbox on\n");
        process->write_to_stdin("osd mode 10\n");
        for(XJSettings::const_iterator it = xjadeo_settings.begin(); it != xjadeo_settings.end(); ++it) {
@@ -233,6 +245,38 @@ VideoMonitor::is_started ()
        return process->is_running();
 }
 
+void
+VideoMonitor::forward_keyevent (unsigned int keyval)
+{
+#if 0 // TODO just 'fake' keyboard input
+                                       GdkEventKey ev;
+                                       ev.type = GDK_KEY_PRESS;
+                                       ev.window = NULL; // XXX
+                                       ev.send_event = TRUE;
+                                       ev.time = 0;
+                                       ev.state = 0;
+                                       ev.keyval = keyval;
+                                       ev.length = 1;
+                                       ev.string = NULL;
+                                       ev.hardware_keycode = 0;
+                                       ev.group = 0;
+
+                                       PublicEditor::instance().on_key_press_event(&ev);
+                                       ev.type = GDK_KEY_RELEASE;
+                                       PublicEditor::instance().on_key_press_event(&ev);
+#else
+       if (keyval == GDK_KEY_space) {
+               if(_session->transport_rolling ()) {
+                       _session->request_transport_speed (0.0);
+               } else {
+                       _session->request_transport_speed (1.0f);
+               }
+       } else if (keyval == GDK_KEY_BackSpace) {
+               _session->goto_start ();
+       }
+#endif
+}
+
 void
 VideoMonitor::parse_output (std::string d, size_t /*s*/)
 {
@@ -261,8 +305,41 @@ VideoMonitor::parse_output (std::string d, size_t /*s*/)
                                         */
                                        process->write_to_stdin("quit\n");
                                }
-                       case 1: /* requested async notifications */
-                       case 3: /* warnings ; command succeeded, but status is negative. */
+#ifdef DEBUG_XJCOM
+                       else
+                               printf("xjadeo: error '%s'\n", line.c_str());
+#endif
+                       break;
+                       case 3: /* async notifications */
+                       {
+                               std::string::size_type equalsign = line.find('=');
+                               std::string::size_type comment = line.find('#');
+                               if (comment != std::string::npos) { line = line.substr(0,comment); }
+                               if (equalsign != std::string::npos) {
+                                       std::string key = line.substr(5, equalsign - 5);
+                                       std::string value = line.substr(equalsign + 1);
+
+                                       if (status == 310 && key=="keypress") {
+                                               /* keyboard event */
+                                               XJKeyEvent((unsigned int)atoi(value));
+                                       }
+#ifdef DEBUG_XJCOM
+                                       else {
+                                               std::string msg = line.substr(5);
+                                               printf("xjadeo: async '%s' -> '%s'\n", key, value);
+                                       }
+#endif
+                               }
+#ifdef DEBUG_XJCOM
+                               else {
+                                       std::string msg = line.substr(5);
+                                       printf("xjadeo: async '%s'\n", msg.c_str());
+                               }
+#endif
+                       } break;
+                       case 1: /* text messages - command reply */
+                               break;
+                       case 8: /* comments / info for humans */
                                break;
                        case 2:
 /* replies:
@@ -341,6 +418,10 @@ VideoMonitor::parse_output (std::string d, size_t /*s*/)
                                                        if (!starting && _session) _session->set_dirty ();
                                                }
                                                xjadeo_settings["set offset"] = value;
+#ifdef DEBUG_XJCOM
+                                       } else {
+                                               printf("xjadeo: '%s' -> '%s'\n", key.c_str(), value.c_str());
+#endif
                                        }
                                }
                        }
index 59b90f5e46fa95ee09e211ce5122024e8bb4cb33..a6edda6e83dae6fc27921bb89ba5a15971a6520d 100644 (file)
@@ -88,6 +88,7 @@ class VideoMonitor : public sigc::trackable , public ARDOUR::SessionHandlePtr, p
        float fps;
        void parse_output (std::string d, size_t s);
        void terminated ();
+       void forward_keyevent (unsigned int);
 
        void parameter_changed (std::string const & p);
 
@@ -106,6 +107,8 @@ class VideoMonitor : public sigc::trackable , public ARDOUR::SessionHandlePtr, p
        int starting;
        int knownstate;
        int osdmode;
+
+       PBD::Signal1<void, unsigned int> XJKeyEvent;
 #if 1
        bool debug_enable;
 #endif