Remove erroneous assert which I added earlier.
[ardour2.git] / gtk2_ardour / imageframe_socket_handler.h
blobd12b8285ef57cf5bd822a6c3d887fa2311b32190
1 /*
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.
20 #ifndef __ardour_gtk_imageframe_socket_handler_h__
21 #define __ardour_gtk_imageframe_socket_handler_h__
23 #include <string>
24 #include <list>
25 #include "ardour_image_compositor_socket.h"
27 class TimeAxisViewItem ;
28 class ImageFrameView ;
29 class MarkerView ;
30 class ImageFrameTimeAxisGroup ;
31 class Editor ;
33 /**
34 * ImageFrameSocketHandler defines the handler between Ardour and an Image Compositor
35 * As this is purely visual, we do all processing within the main gtk loop via
36 * message passing through a socket.
39 class ImageFrameSocketHandler : public sigc::trackable
41 public:
42 /**
43 * Constructs a new ImageFrameSocketHandler to handle communication between Ardour and the Image Compositor
45 * @param ed the PublicEditor
47 ImageFrameSocketHandler(PublicEditor& ed) ;
49 /**
50 * Descructor
51 * this will shutdown the socket if open
53 virtual ~ImageFrameSocketHandler() ;
55 /**
56 * Returns the instance of the ImageFrameSocketHandler
57 * the instance should first be created with createInstance
59 * @return the instance of the ImageFrameSocketHandler
61 static ImageFrameSocketHandler* get_instance() ;
63 /**
64 * call back to handle doing the processing work
65 * This method is added to the gdk main loop and called when there is data
66 * upon the socket.
69 static void image_socket_callback(void *arg, int32_t fd, GdkInputCondition cond) ;
71 /**
72 * Attempt to connect to the image compositor on the specified host and port
74 * @param hostIp the ip address of the image compositor host
75 * @param port the oprt number to attemp the connection on
76 * @return true if the connection was a succees
77 * false otherwise
79 bool connect(const char * hostIp, int32_t port) ;
81 /**
82 * Closes the connection to th Image Compositor
85 void close_connection() ;
86 /**
87 * Returns true if this ImagFrameSocketHandler is currently connected to rthe image compositor
89 * @return true if connected to the image compositor
91 bool is_connected() ;
93 /**
94 * Sets the tag used to describe this input within gtk
95 * this is returned when gdk_input_add is called and is required to remove the input
97 * @param tag the gdk input tag of this input
99 void set_gdk_input_tag(int tag) ;
102 * Returns the gdk input tag of this input
104 * @return the gdk input tag of this input
105 * @see setGdkInputTag
107 int get_gdk_input_tag() ;
111 * Returns the socket file descriptor
113 * @return the Sockt file descriptor
115 int get_socket_descriptor() ;
118 //---------------------------------------------------------------------------------------//
119 // Handle Sending messages to the Image Compositor
121 //----------------------------
122 // ImageFrameTimeAxis Messages
125 * Sends a message stating that the named image frame time axis has been removed
127 * @param track_id the unique id of the removed image frame time axis
128 * @param src the identity of the object that initiated the change
130 void send_imageframe_time_axis_removed(const std::string & track_id, void* src) ;
133 * Sends a message indicating that an ImageFrameTimeAxis has been renamed
135 * @param new_id the new name, or Id, of the track
136 * @param old_id the old name, or Id, of the track
137 * @param src the identity of the object that initiated the change
138 * @param time_axis the time axis that has changed
140 void send_imageframe_time_axis_renamed(const std::string & new_id, const std::string & old_id, void* src, ImageFrameTimeAxis* time_axis) ;
142 //------------------------
143 // MarkerTimeAxis Messages
146 * Sends a message stating that the named marker time axis has been removed
148 * @param track_id the unique id of the removed image frame time axis
149 * @param src the identity of the object that initiated the change
151 void send_marker_time_axis_removed(const std::string & track_id, void* src) ;
154 * Sends a message indicating that an MarkerTimeAxis has been renamed
156 * @param new_id the new name, or Id, of the track
157 * @param old_id the old name, or Id, of the track
158 * @param src the identity of the object that initiated the change
159 * @param time_axis the time axis that has changed
161 void send_marker_time_axis_renamed(const std::string & new_id, const std::string & old_id, void* src, MarkerTimeAxis* time_axis) ;
164 //---------------------------------
165 // ImageFrameTimeAxisGroup Messages
168 * Sends a message stating that the group has been removed
170 * @param group_id the unique id of the removed image frame time axis
171 * @param src the identity of the object that initiated the change
172 * @param group the group that has changed
174 void send_imageframe_time_axis_group_removed(const std::string & group_id, void* src, ImageFrameTimeAxisGroup* group) ;
177 * Send a message indicating that an ImageFrameTimeAxisGroup has been renamed
179 * @param new_id the new name, or Id, of the group
180 * @param old_id the old name, or Id, of the group
181 * @param src the identity of the object that initiated the change
182 * @param group the group that has changed
184 void send_imageframe_time_axis_group_renamed(const std::string & new_id, const std::string & old_id, void* src, ImageFrameTimeAxisGroup* group) ;
187 //---------------------------------
188 // ImageFrameView Messages
191 * Send an Image Frame View Item position changed message
193 * @param pos the new position value
194 * @param src the identity of the object that initiated the change
195 * @param item the time axis item whos position has changed
197 void send_imageframe_view_position_change(nframes_t pos, void* src, ImageFrameView* item) ;
200 * Send a Image Frame View item duration changed message
202 * @param dur the the new duration value
203 * @param src the identity of the object that initiated the change
204 * @param item the item which has had a duration change
206 void send_imageframe_view_duration_change(nframes_t dur, void* src, ImageFrameView* item) ;
209 * Send a message indicating that an ImageFrameView has been renamed
211 * @param item the ImageFrameView which has been renamed
212 * @param src the identity of the object that initiated the change
213 * @param item the renamed item
215 void send_imageframe_view_renamed(const std::string & new_id, const std::string & old_id, void* src, ImageFrameView* item) ;
218 * Send a message indicating that an ImageFrameView item has been removed message
220 * @param item_id the id of the item that was removed
221 * @param src the identity of the object that initiated the change
222 * @param item the removed item
224 void send_imageframe_view_removed(const std::string & item_id, void* src, ImageFrameView* item) ;
226 //---------------------------------
227 // MarkerView Messages
230 * Send a Marker View Item position changed message
232 * @param pos the new position value
233 * @param src the identity of the object that initiated the change
234 * @param item the time axis item whos position has changed
236 void send_marker_view_position_change(nframes_t pos, void* src, MarkerView* item) ;
239 * Send a Marker View item duration changed message
241 * @param dur the new duration value
242 * @param src the identity of the object that initiated the change
243 * @param item the time axis item whos position has changed
245 void send_marker_view_duration_change(nframes_t dur, void* src, MarkerView* item) ;
248 * Send a message indicating that a MarkerView has been renamed
250 * @param new_id the new_id of the object
251 * @param old_id the old_id of the object
252 * @param src the identity of the object that initiated the change
253 * @param item the MarkerView which has been renamed
255 void send_marker_view_renamed(const std::string & new_id, const std::string & old_id, void* src, MarkerView* item) ;
258 * Send a message indicating that a MarkerView item has been removed message
260 * @param item_id the id of the item that was removed
261 * @param src the identity of the object that initiated the change
262 * @param item the MarkerView which has been removed
264 void send_marker_view_removed(const std::string & item_id, void* src, MarkerView* item) ;
267 //---------------------------------------------------------------------------------------//
268 // Emitted Signals
270 /** Emitted if the socket connection is shutdown at the other end */
271 sigc::signal<void> CompositorSocketShutdown ;
273 /** Emitted as a generic error is captured from the socket connection to the animatic compositor */
274 sigc::signal<void> CompositorSocketError ;
277 protected:
280 private:
281 /* I dont like friends :-( */
282 friend class Editor;
285 * Create an new instance of the ImageFrameSocketHandler, if one does not already exist
287 * @param ed the Ardour PublicEditor
289 static ImageFrameSocketHandler* create_instance(PublicEditor& ed) ;
291 //---------------------------------------------------------------------------------------//
292 // Message breakdown ie avoid a big if...then...else
295 * Handle insert item requests
297 * @param msg the received message
299 void handle_insert_message(const char* msg) ;
302 * Handle remove item requests
304 * @param msg the received message
306 void handle_remove_message(const char* msg) ;
309 * Handle rename item requests
311 * @param msg the received message
313 void handle_rename_message(const char* msg) ;
316 * Handle a request for session information
318 * @param msg the received message
320 void handle_request_data(const char* msg) ;
323 * Handle the update of a particular item
325 * @param msg the received message
327 void handle_item_update_message(const char* msg) ;
330 * Handle the selection of an Item
332 * @param msg the received message
334 void handle_item_selected(const char* msg) ;
337 * Handle s session action message
339 * @param msg the received message
341 void handle_session_action(const char* msg) ;
343 //---------------------------------------------------------------------------------------//
344 // handlers for specific insert procedures
347 * Handle the insertion of a new ImaegFrameTimeAxis
349 * @param msg the received message
351 void handle_insert_imageframe_time_axis(const char* msg) ;
354 * Handle the insertion of a new MarkerTimeAxis
356 * @param msg the received message
358 void handle_insert_marker_time_axis(const char* msg) ;
361 * Handle the insertion of a time axis group (a scene)
363 * @param msg the received message
365 void handle_insert_imageframe_group(const char* msg) ;
368 * Handle the insertion of a new ImageFrameItem
370 * @param msg the received message
372 void handle_insert_imageframe_view(const char* msg) ;
375 * Handle the insertion of a new MarkerItem
377 * @param msg the received message
379 void handle_insert_marker_view(const char* msg) ;
381 //---------------------------------------------------------------------------------------//
382 // handlers for specific removal procedures
385 * Handle the removal of an ImageTimeAxis
387 * @param msg the received message
389 void handle_remove_imageframe_time_axis(const char* msg) ;
392 * Handle the removal of an MarkerTimeAxis
394 * @param msg the received message
396 void handle_remove_marker_time_axis(const char* msg) ;
399 * Handle the removal of an ImageFrameTimeAxisGroup
401 * @param msg the received message
403 void handle_remove_imageframe_time_axis_group(const char* msg) ;
406 * Handle the removal of an ImageFrameItem
408 * @param msg the received message
410 void handle_remove_imageframe_view(const char* msg) ;
413 * Handle the removal of an MarkerItem
415 * @param msg the received message
417 void handle_remove_marker_view(const char* msg) ;
419 //---------------------------------------------------------------------------------------//
420 // handlers for the specific rename procedures
423 * Handle the renaming of an ImageTimeAxis
425 * @param msg the received message
427 void handle_rename_imageframe_time_axis(const char* msg) ;
430 * Handle the renaming of an MarkerTimeAxis
432 * @param msg the received message
434 void handle_rename_marker_time_axis(const char* msg) ;
437 * Handle the renaming of an ImageFrameItem
439 * @param msg the received message
441 void handle_rename_imageframe_time_axis_group(const char* msg) ;
444 * Handle the renaming of an ImageFrameItem
446 * @param msg the received message
448 void handle_rename_imageframe_view(const char* msg) ;
451 * Handle the renaming of an Marker
453 * @param msg the received message
455 void handle_rename_marker_view(const char* msg) ;
457 //---------------------------------------------------------------------------------------//
458 // handlers for data request
461 * Handle a request for the sessnio naem fo the current session
462 * We return a failure state if no session is open
464 * @param msg the received message
466 void handle_session_name_request(const char* msg) ;
469 //---------------------------------------------------------------------------------------//
470 // handlers for specific item update changes
473 * Handle ImageFrameView positional changes
475 * @param msg the received message
477 void handle_imageframe_view_position_update(const char* msg) ;
480 * Handle ImageFrameView Duration changes
482 * @param msg the received message
484 void handle_imageframe_view_duration_update(const char* msg) ;
487 * Handle ImageFrameView Position Lock Constraint changes
489 * @param msg the received message
491 void handle_imageframe_position_lock_update(const char* msg) ;
494 * Handle ImageFrameView Maximum Duration changes
496 * @param msg the received message
498 void handle_imageframe_view_max_duration_update(const char* msg) ;
501 * Handle image frame max duration enable constraint changes
503 * @param msg the received message
505 void handle_imageframe_view_max_duration_enable_update(const char* msg) ;
508 * Handle ImageFrameView Minimum Duration changes
510 * @param msg the received message
512 void handle_imageframe_view_min_duration_update(const char* msg) ;
515 * Handle image frame min duration enable constraint changes
517 * @param msg the received message
519 void handle_imageframe_view_min_duration_enable_update(const char* msg) ;
523 * Handle MarkerView position changes
525 * @param msg the received message
527 void handle_marker_view_position_update(const char* msg) ;
530 * Handle MarkerView duration changes
532 * @param msg the received message
534 void handle_marker_view_duration_update(const char* msg) ;
537 * Handle MarkerView Position Lock Constraint changes
539 * @param msg the received message
541 void handle_marker_view_position_lock_update(const char* msg) ;
544 * Handle MarkerView maximum duration changes
546 * @param msg the received message
548 void handle_marker_view_max_duration_update(const char* msg) ;
551 * Handle MarkerView minimum duration changes
553 * @param msg the received message
555 void handle_marker_view_min_duration_update(const char* msg) ;
559 //---------------------------------------------------------------------------------------//
560 // handlers for Session Actions
563 * Handle the opening of a named audio session
565 * @param msg the received message
567 void handle_open_session(const char* msg) ;
570 * Handle the closing of a named audio session
572 * @param msg the received message
574 void handle_closed_session(const char* msg) ;
576 //---------------------------------------------------------------------------------------//
577 // handlers for the shutdown of the Image Compositor
580 * Handle the shutdown message from the image compositor
582 * @param msg the received message
584 void handle_shutdown(const char* msg) ;
587 //---------------------------------------------------------------------------------------//
588 // convenince methods to break up messages
591 * Returns part of the received message as a std::string
593 * @param start the start character
594 * @param num_chars the number of characters to read
595 * @param the message to break apart
596 * @return the sub std::string of the message
598 std::string get_message_part(int start, int32_t num_chars, const char* msg) ;
602 * break up am image item description message
603 * we break the mesage up into the parent Image Track id and size,
604 * the parent group id and size, and the image id and size
606 * @param track_id
607 * @param track_id_size
608 * @param scene_id
609 * @param scene_id_size
610 * @param item_id
611 * @param item_id_size
613 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) ;
616 * Compose a description of the specified image frame view
617 * The description consists of the parent track name size and name,
618 * the parent group name size and name, and the item name size and name
620 * @param ifv the item to compose a description of
621 * @param buffer the buffer to write the description
623 void compose_imageframe_item_desc(ImageFrameView* ifv, std::ostringstream& buffer) ;
626 * Compose a description of the specified marker view
627 * The description consists of the parent track name size and name,
628 * and the item name size and name
630 * @param mv the item to compose a description of
631 * @param buffer the buffer to write the description
633 void compose_marker_item_desc(MarkerView* mv, std::ostringstream& buffer) ;
637 * Returns the ImageFrameView from the specified description
638 * The errcode parameter is used to indicate the item which caused
639 * an error on failure of this method
640 * 0 = suces
641 * 1 = the track item was not found
642 * 2 = the group item was not found
643 * 3 = the imageframe item was not found
645 * @paran track_id the track on which the item is placed
646 * @param group_id the group in which the item is a member
647 * @param item_id the id of the item
648 * @param int32_t reference used for error codes on failure
649 * @param errmsg populated with a description of the error on failure
650 * @return the described item on success, 0 otherwise
652 ImageFrameView* get_imageframe_view_from_desc(const std::string & track_id, const std::string & group_ud, const std::string & item_id, int& errcode, std::string& errmsg) ;
654 //---------------------------------------------------------------------------------------//
655 // Convenince Message Send Methods
658 * Sends a message throught the socket
660 * @param msg the message to send
661 * @return the return value of the socket call
663 int send_message(const std::string & msg) ;
666 * Reads a message from the Socket
668 * @param msg a std::string to populate with the received message
669 * @return the return value from the socket call
671 int read_message(std::string& msg) ;
674 * Convenience method to compose and send a success messasge back to the Image Compositor
677 void send_return_success() ;
680 * Convenience method to compose and send a failure messasge back to the Image Compositor
682 * @param msg the failure message
684 void send_return_failure(const std::string& msg) ;
686 //---------------------------------------------------------------------------------------//
687 // Memebr Data
689 /** Our instance of the socket handler, singleton */
690 static ImageFrameSocketHandler* _instance ;
692 /** The Ardour PublicEditor */
693 PublicEditor& thePublicEditor ;
695 /** the socket file descriptor */
696 int theArdourToCompositorSocket ;
698 /** This stores the 'tag' returned from gdk_input_add, which is required for removing the input */
699 int theGdkInputTag ;
701 } ; /* class ImageFrameSocketHandler */
703 #endif /* __ardour_gtk_imageframe_socket_handler_h__ */