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(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(nframes_t dur, void* src, ImageFrameView* item) ;
210 * Send a message indicating that an ImageFrameView has been renamed
212 * @param item the ImageFrameView which has been renamed
213 * @param src the identity of the object that initiated the change
214 * @param item the renamed item
216 void send_imageframe_view_renamed(const string & new_id, const string & old_id, void* src, ImageFrameView* item) ;
219 * Send a message indicating that an ImageFrameView item has been removed message
221 * @param item_id the id of the item that was removed
222 * @param src the identity of the object that initiated the change
223 * @param item the removed item
225 void send_imageframe_view_removed(const string & item_id, void* src, ImageFrameView* item) ;
227 //---------------------------------
228 // MarkerView Messages
231 * Send a Marker View Item position changed message
233 * @param pos the new position value
234 * @param src the identity of the object that initiated the change
235 * @param item the time axis item whos position has changed
237 void send_marker_view_position_change(nframes_t pos, void* src, MarkerView* item) ;
240 * Send a Marker View item duration changed message
242 * @param dur the new duration value
243 * @param src the identity of the object that initiated the change
244 * @param item the time axis item whos position has changed
246 void send_marker_view_duration_change(nframes_t dur, void* src, MarkerView* item) ;
249 * Send a message indicating that a MarkerView has been renamed
251 * @param new_id the new_id of the object
252 * @param old_id the old_id of the object
253 * @param src the identity of the object that initiated the change
254 * @param item the MarkerView which has been renamed
256 void send_marker_view_renamed(const string & new_id, const string & old_id, void* src, MarkerView* item) ;
259 * Send a message indicating that a MarkerView item has been removed message
261 * @param item_id the id of the item that was removed
262 * @param src the identity of the object that initiated the change
263 * @param item the MarkerView which has been removed
265 void send_marker_view_removed(const string & item_id, void* src, MarkerView* item) ;
268 //---------------------------------------------------------------------------------------//
271 /** Emitted if the socket connection is shutdown at the other end */
272 sigc::signal<void> CompositorSocketShutdown ;
274 /** Emitted as a generic error is captured from the socket connection to the animatic compositor */
275 sigc::signal<void> CompositorSocketError ;
282 /* I dont like friends :-( */
286 * Create an new instance of the ImageFrameSocketHandler, if one does not already exist
288 * @param ed the Ardour PublicEditor
290 static ImageFrameSocketHandler* create_instance(PublicEditor& ed) ;
292 //---------------------------------------------------------------------------------------//
293 // Message breakdown ie avoid a big if...then...else
296 * Handle insert item requests
298 * @param msg the received message
300 void handle_insert_message(const char* msg) ;
303 * Handle remove item requests
305 * @param msg the received message
307 void handle_remove_message(const char* msg) ;
310 * Handle rename item requests
312 * @param msg the received message
314 void handle_rename_message(const char* msg) ;
317 * Handle a request for session information
319 * @param msg the received message
321 void handle_request_data(const char* msg) ;
324 * Handle the update of a particular item
326 * @param msg the received message
328 void handle_item_update_message(const char* msg) ;
331 * Handle the selection of an Item
333 * @param msg the received message
335 void handle_item_selected(const char* msg) ;
338 * Handle s session action message
340 * @param msg the received message
342 void handle_session_action(const char* msg) ;
344 //---------------------------------------------------------------------------------------//
345 // handlers for specific insert procedures
348 * Handle the insertion of a new ImaegFrameTimeAxis
350 * @param msg the received message
352 void handle_insert_imageframe_time_axis(const char* msg) ;
355 * Handle the insertion of a new MarkerTimeAxis
357 * @param msg the received message
359 void handle_insert_marker_time_axis(const char* msg) ;
362 * Handle the insertion of a time axis group (a scene)
364 * @param msg the received message
366 void handle_insert_imageframe_group(const char* msg) ;
369 * Handle the insertion of a new ImageFrameItem
371 * @param msg the received message
373 void handle_insert_imageframe_view(const char* msg) ;
376 * Handle the insertion of a new MarkerItem
378 * @param msg the received message
380 void handle_insert_marker_view(const char* msg) ;
382 //---------------------------------------------------------------------------------------//
383 // handlers for specific removal procedures
386 * Handle the removal of an ImageTimeAxis
388 * @param msg the received message
390 void handle_remove_imageframe_time_axis(const char* msg) ;
393 * Handle the removal of an MarkerTimeAxis
395 * @param msg the received message
397 void handle_remove_marker_time_axis(const char* msg) ;
400 * Handle the removal of an ImageFrameTimeAxisGroup
402 * @param msg the received message
404 void handle_remove_imageframe_time_axis_group(const char* msg) ;
407 * Handle the removal of an ImageFrameItem
409 * @param msg the received message
411 void handle_remove_imageframe_view(const char* msg) ;
414 * Handle the removal of an MarkerItem
416 * @param msg the received message
418 void handle_remove_marker_view(const char* msg) ;
420 //---------------------------------------------------------------------------------------//
421 // handlers for the specific rename procedures
424 * Handle the renaming of an ImageTimeAxis
426 * @param msg the received message
428 void handle_rename_imageframe_time_axis(const char* msg) ;
431 * Handle the renaming of an MarkerTimeAxis
433 * @param msg the received message
435 void handle_rename_marker_time_axis(const char* msg) ;
438 * Handle the renaming of an ImageFrameItem
440 * @param msg the received message
442 void handle_rename_imageframe_time_axis_group(const char* msg) ;
445 * Handle the renaming of an ImageFrameItem
447 * @param msg the received message
449 void handle_rename_imageframe_view(const char* msg) ;
452 * Handle the renaming of an Marker
454 * @param msg the received message
456 void handle_rename_marker_view(const char* msg) ;
458 //---------------------------------------------------------------------------------------//
459 // handlers for data request
462 * Handle a request for the sessnio naem fo the current session
463 * We return a failure state if no session is open
465 * @param msg the received message
467 void handle_session_name_request(const char* msg) ;
470 //---------------------------------------------------------------------------------------//
471 // handlers for specific item update changes
474 * Handle ImageFrameView positional changes
476 * @param msg the received message
478 void handle_imageframe_view_position_update(const char* msg) ;
481 * Handle ImageFrameView Duration changes
483 * @param msg the received message
485 void handle_imageframe_view_duration_update(const char* msg) ;
488 * Handle ImageFrameView Position Lock Constraint changes
490 * @param msg the received message
492 void handle_imageframe_position_lock_update(const char* msg) ;
495 * Handle ImageFrameView Maximum Duration changes
497 * @param msg the received message
499 void handle_imageframe_view_max_duration_update(const char* msg) ;
502 * Handle image frame max duration enable constraint changes
504 * @param msg the received message
506 void handle_imageframe_view_max_duration_enable_update(const char* msg) ;
509 * Handle ImageFrameView Minimum Duration changes
511 * @param msg the received message
513 void handle_imageframe_view_min_duration_update(const char* msg) ;
516 * Handle image frame min duration enable constraint changes
518 * @param msg the received message
520 void handle_imageframe_view_min_duration_enable_update(const char* msg) ;
524 * Handle MarkerView position changes
526 * @param msg the received message
528 void handle_marker_view_position_update(const char* msg) ;
531 * Handle MarkerView duration changes
533 * @param msg the received message
535 void handle_marker_view_duration_update(const char* msg) ;
538 * Handle MarkerView Position Lock Constraint changes
540 * @param msg the received message
542 void handle_marker_view_position_lock_update(const char* msg) ;
545 * Handle MarkerView maximum duration changes
547 * @param msg the received message
549 void handle_marker_view_max_duration_update(const char* msg) ;
552 * Handle MarkerView minimum duration changes
554 * @param msg the received message
556 void handle_marker_view_min_duration_update(const char* msg) ;
560 //---------------------------------------------------------------------------------------//
561 // handlers for Session Actions
564 * Handle the opening of a named audio session
566 * @param msg the received message
568 void handle_open_session(const char* msg) ;
571 * Handle the closing of a named audio session
573 * @param msg the received message
575 void handle_closed_session(const char* msg) ;
577 //---------------------------------------------------------------------------------------//
578 // handlers for the shutdown of the Image Compositor
581 * Handle the shutdown message from the image compositor
583 * @param msg the received message
585 void handle_shutdown(const char* msg) ;
588 //---------------------------------------------------------------------------------------//
589 // convenince methods to break up messages
592 * Returns part of the received message as a std::string
594 * @param start the start character
595 * @param num_chars the number of characters to read
596 * @param the message to break apart
597 * @return the sub string of the message
599 std::string get_message_part(int start, int32_t num_chars, const char* msg) ;
603 * break up am image item description message
604 * we break the mesage up into the parent Image Track id and size,
605 * the parent group id and size, and the image id and size
608 * @param track_id_size
610 * @param scene_id_size
612 * @param item_id_size
614 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) ;
617 * Compose a description of the specified image frame view
618 * The description consists of the parent track name size and name,
619 * the parent group name size and name, and the item name size and name
621 * @param ifv the item to compose a description of
622 * @param buffer the buffer to write the description
624 void compose_imageframe_item_desc(ImageFrameView* ifv, std::ostringstream& buffer) ;
627 * Compose a description of the specified marker view
628 * The description consists of the parent track name size and name,
629 * and the item name size and name
631 * @param mv the item to compose a description of
632 * @param buffer the buffer to write the description
634 void compose_marker_item_desc(MarkerView* mv, std::ostringstream& buffer) ;
638 * Returns the ImageFrameView from the specified description
639 * The errcode parameter is used to indicate the item which caused
640 * an error on failure of this method
642 * 1 = the track item was not found
643 * 2 = the group item was not found
644 * 3 = the imageframe item was not found
646 * @paran track_id the track on which the item is placed
647 * @param group_id the group in which the item is a member
648 * @param item_id the id of the item
649 * @param int32_t reference used for error codes on failure
650 * @param errmsg populated with a description of the error on failure
651 * @return the described item on success, 0 otherwise
653 ImageFrameView* get_imageframe_view_from_desc(const string & track_id, const string & group_ud, const string & item_id, int& errcode, std::string& errmsg) ;
655 //---------------------------------------------------------------------------------------//
656 // Convenince Message Send Methods
659 * Sends a message throught the socket
661 * @param msg the message to send
662 * @return the return value of the socket call
664 int send_message(const string & msg) ;
667 * Reads a message from the Socket
669 * @param msg a string to populate with the received message
670 * @return the return value from the socket call
672 int read_message(std::string& msg) ;
675 * Convenience method to compose and send a success messasge back to the Image Compositor
678 void send_return_success() ;
681 * Convenience method to compose and send a failure messasge back to the Image Compositor
683 * @param msg the failure message
685 void send_return_failure(const std::string& msg) ;
687 //---------------------------------------------------------------------------------------//
690 /** Our instance of the socket handler, singleton */
691 static ImageFrameSocketHandler* _instance ;
693 /** The Ardour PublicEditor */
694 PublicEditor& thePublicEditor ;
696 /** the socket file descriptor */
697 int theArdourToCompositorSocket ;
699 /** This stores the 'tag' returned from gdk_input_add, which is required for removing the input */
702 } ; /* class ImageFrameSocketHandler */
704 #endif /* __ardour_gtk_imageframe_socket_handler_h__ */