2 Copyright (C) 2003 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_gtk_imageframe_socket_handler_h__
22 #define __ardour_gtk_imageframe_socket_handler_h__
27 #include "ardour_image_compositor_socket.h"
29 class TimeAxisViewItem ;
30 class ImageFrameView ;
32 class ImageFrameTimeAxisGroup ;
35 * ImageFrameSocketHandler defines the handler between Ardour and an Image Compositor
36 * As this is purely visual, we do all processing within the main gtk loop via
37 * message passing through a socket.
40 class ImageFrameSocketHandler : public sigc::trackable
44 * Constructs a new ImageFrameSocketHandler to handle communication between Ardour and the Image Compositor
46 * @param ed the PublicEditor
48 ImageFrameSocketHandler(PublicEditor& ed) ;
52 * this will shutdown the socket if open
54 virtual ~ImageFrameSocketHandler() ;
57 * Returns the instance of the ImageFrameSocketHandler
58 * the instance should first be created with createInstance
60 * @return the instance of the ImageFrameSocketHandler
62 static ImageFrameSocketHandler* get_instance() ;
65 * call back to handle doing the processing work
66 * This method is added to the gdk main loop and called when there is data
70 static void image_socket_callback(void *arg, int32_t fd, GdkInputCondition cond) ;
73 * Attempt to connect to the image compositor on the specified host and port
75 * @param hostIp the ip address of the image compositor host
76 * @param port the oprt number to attemp the connection on
77 * @return true if the connection was a succees
80 bool connect(const char * hostIp, int32_t port) ;
83 * Closes the connection to th Image Compositor
86 void close_connection() ;
88 * Returns true if this ImagFrameSocketHandler is currently connected to rthe image compositor
90 * @return true if connected to the image compositor
95 * Sets the tag used to describe this input within gtk
96 * this is returned when gdk_input_add is called and is required to remove the input
98 * @param tag the gdk input tag of this input
100 void set_gdk_input_tag(int tag) ;
103 * Returns the gdk input tag of this input
105 * @return the gdk input tag of this input
106 * @see setGdkInputTag
108 int get_gdk_input_tag() ;
112 * Returns the socket file descriptor
114 * @return the Sockt file descriptor
116 int get_socket_descriptor() ;
119 //---------------------------------------------------------------------------------------//
120 // Handle Sending messages to the Image Compositor
122 //----------------------------
123 // ImageFrameTimeAxis Messages
126 * Sends a message stating that the named image frame time axis has been removed
128 * @param track_id the unique id of the removed image frame time axis
129 * @param src the identity of the object that initiated the change
131 void send_imageframe_time_axis_removed(const string & track_id, void* src) ;
134 * Sends a message indicating that an ImageFrameTimeAxis has been renamed
136 * @param new_id the new name, or Id, of the track
137 * @param old_id the old name, or Id, of the track
138 * @param src the identity of the object that initiated the change
139 * @param time_axis the time axis that has changed
141 void send_imageframe_time_axis_renamed(const string & new_id, const string & old_id, void* src, ImageFrameTimeAxis* time_axis) ;
143 //------------------------
144 // MarkerTimeAxis Messages
147 * Sends a message stating that the named marker time axis has been removed
149 * @param track_id the unique id of the removed image frame time axis
150 * @param src the identity of the object that initiated the change
152 void send_marker_time_axis_removed(const string & track_id, void* src) ;
155 * Sends a message indicating that an MarkerTimeAxis has been renamed
157 * @param new_id the new name, or Id, of the track
158 * @param old_id the old name, or Id, of the track
159 * @param src the identity of the object that initiated the change
160 * @param time_axis the time axis that has changed
162 void send_marker_time_axis_renamed(const string & new_id, const string & old_id, void* src, MarkerTimeAxis* time_axis) ;
165 //---------------------------------
166 // ImageFrameTimeAxisGroup Messages
169 * Sends a message stating that the group has been removed
171 * @param group_id the unique id of the removed image frame time axis
172 * @param src the identity of the object that initiated the change
173 * @param group the group that has changed
175 void send_imageframe_time_axis_group_removed(const string & group_id, void* src, ImageFrameTimeAxisGroup* group) ;
178 * Send a message indicating that an ImageFrameTimeAxisGroup has been renamed
180 * @param new_id the new name, or Id, of the group
181 * @param old_id the old name, or Id, of the group
182 * @param src the identity of the object that initiated the change
183 * @param group the group that has changed
185 void send_imageframe_time_axis_group_renamed(const string & new_id, const string & old_id, void* src, ImageFrameTimeAxisGroup* group) ;
188 //---------------------------------
189 // ImageFrameView Messages
192 * Send an Image Frame View Item position changed message
194 * @param pos the new position value
195 * @param src the identity of the object that initiated the change
196 * @param item the time axis item whos position has changed
198 void send_imageframe_view_position_change(jack_nframes_t pos, void* src, ImageFrameView* item) ;
201 * Send a Image Frame View item duration changed message
203 * @param dur the the new duration value
204 * @param src the identity of the object that initiated the change
205 * @param item the item which has had a duration change
207 void send_imageframe_view_duration_change(jack_nframes_t dur, void* src, ImageFrameView* item) ;
210 * Send a message indicating that an ImageFrameView has been renamed
212 * @param new_id the renamed item's new ID
213 * @param old_id the renamed item's old ID
214 * @param src the identity of the object that initiated the change
215 * @param item the ImageFrameView which has been renamed
217 void send_imageframe_view_renamed(const string & new_id, const string & old_id, void* src, ImageFrameView* item) ;
220 * Send a message indicating that an ImageFrameView item has been removed message
222 * @param item_id the id of the item that was removed
223 * @param src the identity of the object that initiated the change
224 * @param item the removed item
226 void send_imageframe_view_removed(const string & item_id, void* src, ImageFrameView* item) ;
228 //---------------------------------
229 // MarkerView Messages
232 * Send a Marker View Item position changed message
234 * @param pos the new position value
235 * @param src the identity of the object that initiated the change
236 * @param item the time axis item whos position has changed
238 void send_marker_view_position_change(jack_nframes_t pos, void* src, MarkerView* item) ;
241 * Send a Marker View item duration changed message
243 * @param dur the new duration value
244 * @param src the identity of the object that initiated the change
245 * @param item the time axis item whos position has changed
247 void send_marker_view_duration_change(jack_nframes_t dur, void* src, MarkerView* item) ;
250 * Send a message indicating that a MarkerView has been renamed
252 * @param new_id the new_id of the object
253 * @param old_id the old_id of the object
254 * @param src the identity of the object that initiated the change
255 * @param item the MarkerView which has been renamed
257 void send_marker_view_renamed(const string & new_id, const string & old_id, void* src, MarkerView* item) ;
260 * Send a message indicating that a MarkerView item has been removed message
262 * @param item_id the id of the item that was removed
263 * @param src the identity of the object that initiated the change
264 * @param item the MarkerView which has been removed
266 void send_marker_view_removed(const string & item_id, void* src, MarkerView* item) ;
269 //---------------------------------------------------------------------------------------//
272 /** Emitted if the socket connection is shutdown at the other end */
273 sigc::signal<void> CompositorSocketShutdown ;
275 /** Emitted as a generic error is captured from the socket connection to the animatic compositor */
276 sigc::signal<void> CompositorSocketError ;
283 /* I dont like friends :-( */
287 * Create an new instance of the ImageFrameSocketHandler, if one does not already exist
289 * @param ed the Ardour PublicEditor
291 static ImageFrameSocketHandler* create_instance(PublicEditor& ed) ;
293 //---------------------------------------------------------------------------------------//
294 // Message breakdown ie avoid a big if...then...else
297 * Handle insert item requests
299 * @param msg the received message
301 void handle_insert_message(const char* msg) ;
304 * Handle remove item requests
306 * @param msg the received message
308 void handle_remove_message(const char* msg) ;
311 * Handle rename item requests
313 * @param msg the received message
315 void handle_rename_message(const char* msg) ;
318 * Handle a request for session information
320 * @param msg the received message
322 void handle_request_data(const char* msg) ;
325 * Handle the update of a particular item
327 * @param msg the received message
329 void handle_item_update_message(const char* msg) ;
332 * Handle the selection of an Item
334 * @param msg the received message
336 void handle_item_selected(const char* msg) ;
339 * Handle s session action message
341 * @param msg the received message
343 void handle_session_action(const char* msg) ;
345 //---------------------------------------------------------------------------------------//
346 // handlers for specific insert procedures
349 * Handle the insertion of a new ImaegFrameTimeAxis
351 * @param msg the received message
353 void handle_insert_imageframe_time_axis(const char* msg) ;
356 * Handle the insertion of a new MarkerTimeAxis
358 * @param msg the received message
360 void handle_insert_marker_time_axis(const char* msg) ;
363 * Handle the insertion of a time axis group (a scene)
365 * @param msg the received message
367 void handle_insert_imageframe_group(const char* msg) ;
370 * Handle the insertion of a new ImageFrameItem
372 * @param msg the received message
374 void handle_insert_imageframe_view(const char* msg) ;
377 * Handle the insertion of a new MarkerItem
379 * @param msg the received message
381 void handle_insert_marker_view(const char* msg) ;
383 //---------------------------------------------------------------------------------------//
384 // handlers for specific removal procedures
387 * Handle the removal of an ImageTimeAxis
389 * @param msg the received message
391 void handle_remove_imageframe_time_axis(const char* msg) ;
394 * Handle the removal of an MarkerTimeAxis
396 * @param msg the received message
398 void handle_remove_marker_time_axis(const char* msg) ;
401 * Handle the removal of an ImageFrameTimeAxisGroup
403 * @param msg the received message
405 void handle_remove_imageframe_time_axis_group(const char* msg) ;
408 * Handle the removal of an ImageFrameItem
410 * @param msg the received message
412 void handle_remove_imageframe_view(const char* msg) ;
415 * Handle the removal of an MarkerItem
417 * @param msg the received message
419 void handle_remove_marker_view(const char* msg) ;
421 //---------------------------------------------------------------------------------------//
422 // handlers for the specific rename procedures
425 * Handle the renaming of an ImageTimeAxis
427 * @param msg the received message
429 void handle_rename_imageframe_time_axis(const char* msg) ;
432 * Handle the renaming of an MarkerTimeAxis
434 * @param msg the received message
436 void handle_rename_marker_time_axis(const char* msg) ;
439 * Handle the renaming of an ImageFrameItem
441 * @param msg the received message
443 void handle_rename_imageframe_time_axis_group(const char* msg) ;
446 * Handle the renaming of an ImageFrameItem
448 * @param msg the received message
450 void handle_rename_imageframe_view(const char* msg) ;
453 * Handle the renaming of an Marker
455 * @param msg the received message
457 void handle_rename_marker_view(const char* msg) ;
459 //---------------------------------------------------------------------------------------//
460 // handlers for data request
463 * Handle a request for the sessnio naem fo the current session
464 * We return a failure state if no session is open
466 * @param msg the received message
468 void handle_session_name_request(const char* msg) ;
471 //---------------------------------------------------------------------------------------//
472 // handlers for specific item update changes
475 * Handle ImageFrameView positional changes
477 * @param msg the received message
479 void handle_imageframe_view_position_update(const char* msg) ;
482 * Handle ImageFrameView Duration changes
484 * @param msg the received message
486 void handle_imageframe_view_duration_update(const char* msg) ;
489 * Handle ImageFrameView Position Lock Constraint changes
491 * @param msg the received message
493 void handle_imageframe_position_lock_update(const char* msg) ;
496 * Handle ImageFrameView Maximum Duration changes
498 * @param msg the received message
500 void handle_imageframe_view_max_duration_update(const char* msg) ;
503 * Handle image frame max duration enable constraint changes
505 * @param msg the received message
507 void handle_imageframe_view_max_duration_enable_update(const char* msg) ;
510 * Handle ImageFrameView Minimum Duration changes
512 * @param msg the received message
514 void handle_imageframe_view_min_duration_update(const char* msg) ;
517 * Handle image frame min duration enable constraint changes
519 * @param msg the received message
521 void handle_imageframe_view_min_duration_enable_update(const char* msg) ;
525 * Handle MarkerView position changes
527 * @param msg the received message
529 void handle_marker_view_position_update(const char* msg) ;
532 * Handle MarkerView duration changes
534 * @param msg the received message
536 void handle_marker_view_duration_update(const char* msg) ;
539 * Handle MarkerView Position Lock Constraint changes
541 * @param msg the received message
543 void handle_marker_view_position_lock_update(const char* msg) ;
546 * Handle MarkerView maximum duration changes
548 * @param msg the received message
550 void handle_marker_view_max_duration_update(const char* msg) ;
553 * Handle MarkerView minimum duration changes
555 * @param msg the received message
557 void handle_marker_view_min_duration_update(const char* msg) ;
561 //---------------------------------------------------------------------------------------//
562 // handlers for Session Actions
565 * Handle the opening of a named audio session
567 * @param msg the received message
569 void handle_open_session(const char* msg) ;
572 * Handle the closing of a named audio session
574 * @param msg the received message
576 void handle_closed_session(const char* msg) ;
578 //---------------------------------------------------------------------------------------//
579 // handlers for the shutdown of the Image Compositor
582 * Handle the shutdown message from the image compositor
584 * @param msg the received message
586 void handle_shutdown(const char* msg) ;
589 //---------------------------------------------------------------------------------------//
590 // convenince methods to break up messages
593 * Returns part of the received message as a std::string
595 * @param start the start character
596 * @param num_chars the number of characters to read
597 * @param the message to break apart
598 * @return the sub string of the message
600 std::string get_message_part(int start, int32_t num_chars, const char* msg) ;
604 * break up am image item description message
605 * we break the mesage up into the parent Image Track id and size,
606 * the parent group id and size, and the image id and size
609 * @param track_id_size
611 * @param scene_id_size
613 * @param item_id_size
615 void decompose_imageframe_item_desc(const char* msg, int& position, std::string& track_id, int& track_id_size, std::string& scene_id, int& scene_id_size, std::string& item_id, int& item_id_size) ;
618 * Compose a description of the specified image frame view
619 * The description consists of the parent track name size and name,
620 * the parent group name size and name, and the item name size and name
622 * @param ifv the item to compose a description of
623 * @param buffer the buffer to write the description
625 void compose_imageframe_item_desc(ImageFrameView* ifv, std::ostringstream& buffer) ;
628 * Compose a description of the specified marker view
629 * The description consists of the parent track name size and name,
630 * and the item name size and name
632 * @param mv the item to compose a description of
633 * @param buffer the buffer to write the description
635 void compose_marker_item_desc(MarkerView* mv, std::ostringstream& buffer) ;
639 * Returns the ImageFrameView from the specified description
640 * The errcode parameter is used to indicate the item which caused
641 * an error on failure of this method
643 * 1 = the track item was not found
644 * 2 = the group item was not found
645 * 3 = the imageframe item was not found
647 * @paran track_id the track on which the item is placed
648 * @param group_id the group in which the item is a member
649 * @param item_id the id of the item
650 * @param int32_t reference used for error codes on failure
651 * @param errmsg populated with a description of the error on failure
652 * @return the described item on success, 0 otherwise
654 ImageFrameView* get_imageframe_view_from_desc(const string & track_id, const string & group_ud, const string & item_id, int& errcode, std::string& errmsg) ;
656 //---------------------------------------------------------------------------------------//
657 // Convenince Message Send Methods
660 * Sends a message throught the socket
662 * @param msg the message to send
663 * @return the return value of the socket call
665 int send_message(const string & msg) ;
668 * Reads a message from the Socket
670 * @param msg a string to populate with the received message
671 * @return the return value from the socket call
673 int read_message(std::string& msg) ;
676 * Convenience method to compose and send a success messasge back to the Image Compositor
679 void send_return_success() ;
682 * Convenience method to compose and send a failure messasge back to the Image Compositor
684 * @param msg the failure message
686 void send_return_failure(const std::string& msg) ;
688 //---------------------------------------------------------------------------------------//
691 /** Our instance of the socket handler, singleton */
692 static ImageFrameSocketHandler* _instance ;
694 /** The Ardour PublicEditor */
695 PublicEditor& thePublicEditor ;
697 /** the socket file descriptor */
698 int theArdourToCompositorSocket ;
700 /** This stores the 'tag' returned from gdk_input_add, which is required for removing the input */
703 } ; /* class ImageFrameSocketHandler */
705 #endif /* __ardour_gtk_imageframe_socket_handler_h__ */