1 // MediaRoutingView.h 2 // c.lenz 9oct99 3 // 4 // PURPOSE 5 // Provide a simple interface for the BeOS/Genki media system. 6 // Displays all the currently running ('live') media nodes, 7 // and represents the connections between them visually. 8 // 9 // NOTES 10 // 11 // *** 9oct99: replaced grid-based version 12 // 13 // HISTORY 14 // e.moon 6may99: first stab 15 // c.lenz 6oct99: starting change to DiagramView impl 16 17 #ifndef __MediaRoutingView__H__ 18 #define __MediaRoutingView__H__ 19 20 // DiagramView 21 #include "DiagramView.h" 22 23 // Media Kit 24 #include "MediaDefs.h" 25 26 #include <Entry.h> 27 #include <List.h> 28 #include <Message.h> 29 30 #include "IStateArchivable.h" 31 32 #include "cortex_defs.h" 33 __BEGIN_CORTEX_NAMESPACE 34 35 // MediaRoutingView 36 class MediaNodePanel; 37 class MediaWire; 38 // NodeManager 39 class RouteAppNodeManager; 40 class NodeGroup; 41 class NodeRef; 42 class Connection; 43 // RouteApp 44 class NodeSetIOContext; 45 46 class MediaRoutingView : 47 public DiagramView, 48 public IStateArchivable { 49 typedef DiagramView _inherited; 50 51 public: // *** constants 52 53 // [e.moon 26oct99] moved definitions to MediaRoutingView.cpp 54 static float M_CLEANUP_H_GAP; 55 static float M_CLEANUP_V_GAP; 56 static float M_CLEANUP_H_MARGIN; 57 static float M_CLEANUP_V_MARGIN; 58 59 // [e.moon 7dec99] enum now a named type 60 enum layout_t 61 { 62 M_ICON_VIEW = 1, 63 M_MINI_ICON_VIEW 64 }; 65 66 public: // messages 67 68 enum message_t { 69 // INBOUND 70 // "layout" int32: M_ICON_VIEW / M_MINI_ICON_VIEW 71 M_LAYOUT_CHANGED, 72 73 // INBOUND 74 M_CLEANUP_REQUESTED, 75 76 // INBOUND 77 // release/delete node 78 // "nodeID" [u]int32: node to release 79 M_RELEASE_NODE, 80 81 // INBOUND 82 M_SELECT_ALL, 83 84 // INBOUND 85 M_DELETE_SELECTION, 86 87 // OUTBOUND 88 // describes a selected node (sent to owning window) 89 // "nodeID" int32 90 M_NODE_SELECTED, 91 92 // OUTBOUND 93 // describes a selected group (sent to owning window) 94 // "groupID" int32 95 M_GROUP_SELECTED, 96 97 // INBOUND 98 // requests that the currently selected node/group be broadcast 99 // back to the owning window 100 M_BROADCAST_SELECTION, 101 102 // INBOUND 103 // request to change the selected nodes cycling mode (on/off) 104 // "cycle" bool 105 M_NODE_CHANGE_CYCLING, 106 107 // INBOUND 108 // request to change the selected nodes run mode 109 // "run_mode" int32 110 M_NODE_CHANGE_RUN_MODE, 111 112 // INBOUND 113 // request to start/stop the selected node(s) as a time source 114 // instantly 115 // [e.moon 5dec99] 116 M_NODE_START_TIME_SOURCE, 117 M_NODE_STOP_TIME_SOURCE, 118 119 // INBOUND 120 // call BControllable::StartControlPanel for the node specified 121 // in the field "nodeID" (int32) 122 // [c.lenz 24dec99] 123 M_NODE_START_CONTROL_PANEL, 124 125 // INBOUND 126 // set the given group's GROUP_LOCKED flag 127 // [em 1feb00] 128 // "groupID" int32 129 // "locked" bool 130 M_GROUP_SET_LOCKED, 131 132 // INBOUND 133 // open ParameterWindow for selected nodes 134 // [c.lenz 17feb2000] 135 M_NODE_TWEAK_PARAMETERS, 136 137 // INBOUND 138 // sent to the RouteWindow for displaying error 139 // messages in the status bar if available 140 // "text" string 141 // "error" bool (optional) 142 M_SHOW_ERROR_MESSAGE 143 }; 144 145 public: // *** members 146 147 RouteAppNodeManager* const manager; 148 149 public: // *** ctor/dtor 150 151 MediaRoutingView( 152 RouteAppNodeManager *nodeManager, 153 BRect frame, 154 const char *name, 155 uint32 resizeMode = B_FOLLOW_ALL_SIDES); 156 157 virtual ~MediaRoutingView(); 158 159 public: // *** DiagramView impl 160 161 virtual void connectionAborted( 162 DiagramEndPoint *fromWhich); 163 164 virtual void connectionEstablished( 165 DiagramEndPoint *fromWhich, 166 DiagramEndPoint *toWhich); 167 168 DiagramWire *createWire( 169 DiagramEndPoint *fromWhich, 170 DiagramEndPoint *woWhich); 171 172 DiagramWire *createWire( 173 DiagramEndPoint *fromWhich); 174 175 virtual void BackgroundMouseDown( 176 BPoint point, 177 uint32 buttons, 178 uint32 clicks); 179 180 virtual void MessageDropped( 181 BPoint point, 182 BMessage *message); 183 184 virtual void SelectionChanged(); 185 186 public: // *** BView impl 187 188 virtual void AttachedToWindow(); 189 190 virtual void AllAttached(); 191 192 virtual void DetachedFromWindow(); 193 194 virtual void KeyDown( 195 const char *bytes, 196 int32 count); 197 198 virtual void Pulse(); 199 200 public: // *** BHandler impl 201 202 virtual void MessageReceived( 203 BMessage *message); 204 205 public: // *** accessors 206 207 layout_t getLayout() const 208 { return m_layout; } 209 210 public: // *** operations 211 212 // returns coordinates for a free area where the panel 213 // could be positioned; uses the M_CLEANUP_* settings 214 // and positions producers at the left, consumer at the 215 // right and filters in the middle 216 BPoint findFreePositionFor( 217 const MediaNodePanel *panel) const; 218 219 public: // *** IStateArchivable 220 221 status_t importState( 222 const BMessage* archive); 223 224 status_t exportState( 225 BMessage* archive) const; 226 227 // [e.moon 8dec99] subset support 228 status_t importStateFor( 229 const NodeSetIOContext* context, 230 const BMessage* archive); 231 232 status_t exportStateFor( 233 const NodeSetIOContext* context, 234 BMessage* archive) const; 235 236 protected: // *** operations 237 238 // adjust the default object sizes to the current 239 // layout and font size and rearrange if necessary 240 void layoutChanged( 241 layout_t layout); 242 243 // aligns the panels on a grid according to their node_kind 244 void cleanUp(); 245 246 // displays a context menu at a given position 247 void showContextMenu( 248 BPoint point); 249 250 // will currently display a BAlert; this should change sometime 251 // in the future! 252 void showErrorMessage( 253 BString message, 254 status_t error); 255 256 private: // *** children management 257 258 // adds a panel representation of a live media node to the view 259 status_t _addPanelFor( 260 media_node_id id, 261 BPoint point); 262 263 // tries to find the panel to a given media node 264 status_t _findPanelFor( 265 media_node_id id, 266 MediaNodePanel **outPanel) const; 267 268 // removes the panel of a given media node 269 status_t _removePanelFor( 270 media_node_id); 271 272 // adds a wire represenation of a media kit connection 273 status_t _addWireFor( 274 Connection &connection); 275 276 // finds the ui rep of a given Connection object 277 status_t _findWireFor( 278 uint32 connectionID, 279 MediaWire **wire) const; 280 281 // removes the wire 282 status_t _removeWireFor( 283 uint32 connectionID); 284 285 private: // *** internal methods 286 287 // iterates through all selected MediaNodePanels and sets the 288 // 'cycling' state for each to cycle 289 void _changeCyclingForSelection( 290 bool cycle); 291 292 // iterates through all selected MediaNodePanels and sets the 293 // RunMode for each to mode; 0 is interpreted as '(same as group)' 294 void _changeRunModeForSelection( 295 uint32 mode); 296 297 void _openInfoWindowsForSelection(); 298 299 void _openParameterWindowsForSelection(); 300 301 void _startControlPanelsForSelection(); 302 303 // tries to release every node in the current selection, or to 304 // disconnect wires if those were selected 305 void _deleteSelection(); 306 307 void _addShortcuts(); 308 309 void _initLayout(); 310 311 // populates the view with all nodes currently in the NodeManager 312 void _initContent(); 313 314 void _checkDroppedFile( 315 entry_ref *ref, 316 BPoint dropPoint); 317 318 void _changeBackground( 319 entry_ref *ref); 320 321 void _changeBackground( 322 rgb_color color); 323 324 // adjust scroll bar ranges 325 void _adjustScrollBars(); 326 327 void _broadcastSelection() const; 328 329 // find & remove an entry in m_inactiveNodeState 330 status_t _fetchInactiveNodeState( 331 MediaNodePanel* forPanel, 332 BMessage* outMessage); 333 334 void _emptyInactiveNodeState(); 335 336 private: 337 338 // the current layout 339 layout_t m_layout; 340 341 // current new-group-name index 342 uint32 m_nextGroupNumber; 343 344 // holds the id of the node instantiated last thru d&d 345 media_node_id m_lastDroppedNode; 346 347 // the point at which above node was dropped 348 BPoint m_lastDropPoint; 349 350 // holds a pointer to the currently dragged wire (if any) 351 MediaWire *m_draggedWire; 352 353 // stores location of the background bitmap (invalid if no 354 // background bitmap has been set.) 355 // [e.moon 1dec99] 356 BEntry m_backgroundBitmapEntry; 357 358 // state info for currently inactive nodes (cached from importState()) 359 BList m_inactiveNodeState; 360 }; 361 362 __END_CORTEX_NAMESPACE 363 #endif /* __MediaRoutingView_H__ */ 364