void MediaRoutingView::_initContent()
{
	D_METHOD(("MediaRoutingView::_initContent()\n"));

	Autolock lock(manager);

	void *cookie = 0;
	NodeRef *ref;
	while (manager->getNextRef(&ref, &cookie) == B_OK)
	{
		// add self as observer
		add_observer(this, ref);
		// create & place node view (+++++ defer until observer status confirmed!)
		_addPanelFor(ref->id(), BPoint(M_CLEANUP_H_MARGIN, M_CLEANUP_V_MARGIN));
	}
	cookie = 0;
	Connection connection;
	while (manager->getNextConnection(&connection, &cookie) == B_OK)
	{
		_addWireFor(connection);
	}

	// create default groups
	NodeGroup* group;
	NodeRef* videoIn = manager->videoInputNode();
	if (videoIn)
	{
		group = manager->createGroup("Video Input");
		group->setRunMode(BMediaNode::B_RECORDING);
		group->addNode(videoIn);
	}
	NodeRef* audioIn = manager->audioInputNode();
	if (audioIn)
	{
		group = manager->createGroup("Audio Input");
		group->setRunMode(BMediaNode::B_RECORDING);
		group->addNode(audioIn);
	}
	NodeRef* videoOut = manager->videoOutputNode();
	if (videoOut)
	{
		group = manager->createGroup("Video Output");
		group->addNode(videoOut);
	}
}
void MediaRoutingView::MessageReceived(
	BMessage* message)
{
	D_METHOD(("MediaRoutingView::MessageReceived()\n"));

	switch (message->what)
	{
		case B_MEDIA_NODE_CREATED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_NODE_CREATED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("media_node_id", &type, &count) == B_OK)
			{
				for(int32 n = 0; n < count; n++) 
				{
					int32 id;
					if (message->FindInt32("media_node_id", n, &id) == B_OK)
					{
						// [e.moon 8dec99] allow for existing panel
						MediaNodePanel* panel;
						if(_findPanelFor(id, &panel) < B_OK)
							_addPanelFor(id, BPoint(5.0, 5.0));
					}
				}
			}
			break;
		}
		case B_MEDIA_NODE_DELETED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_NODE_DELETED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("media_node_id", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++) 
				{
					int32 id;
					if (message->FindInt32("media_node_id", n, &id) == B_OK)
					{
						_removePanelFor(id);
					}
				}
			}			
			break;
		}
		case B_MEDIA_CONNECTION_MADE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_CONNECTION_MADE)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("output", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++)
				{
					media_output output;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("output", B_RAW_TYPE, n, &data, &dataSize) == B_OK)
					{
						output = *reinterpret_cast<const media_output *>(data);
						Connection connection;
						if (manager->findConnection(output.node.node, output.source, &connection) == B_OK)
						{
							_addWireFor(connection);
						}
					}
				}
			}
			break;
		}
		case B_MEDIA_CONNECTION_BROKEN:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_CONNECTION_BROKEN)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("__connection_id", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++)
				{
					int32 id;
					if (message->FindInt32("__connection_id", n, &id) == B_OK)
					{
						_removeWireFor(id);
					}	
				}
			}
			break;
		}
		case B_MEDIA_FORMAT_CHANGED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_FORMAT_CHANGED)\n"));
			
			media_node_id nodeID;
			if(message->FindInt32("__source_node_id", &nodeID) < B_OK)
				break;

			uint32 connectionID;
			if(message->FindInt32("__connection_id", (int32*)&connectionID) < B_OK)
				break;

			media_source* source;
			ssize_t dataSize;
			if(message->FindData("be:source", B_RAW_TYPE, (const void**)&source, &dataSize) < B_OK)
				break;
				
			MediaWire* wire;
			if(_findWireFor(connectionID, &wire) == B_OK) {
				// copy new connection data
				manager->findConnection(nodeID, *source, &wire->connection);
			}
			break;
		}
		case M_CLEANUP_REQUESTED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_M_CLEANUP_REQUESTED)\n"));
			cleanUp();
			break;
		}
		case M_SELECT_ALL:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_SELECT_ALL)\n"));
			selectAll(DiagramItem::M_BOX);
			break;
		}
		case M_DELETE_SELECTION:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_DELETE_SELECTION)\n"));
			_deleteSelection();
			break;
		}
		case M_NODE_CHANGE_CYCLING:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_CYCLING_CHANGED)\n"));
			bool cycle;
			if (message->FindBool("cycle", &cycle) == B_OK)
			{
				_changeCyclingForSelection(cycle);
			}
			break;
		}
		case M_NODE_CHANGE_RUN_MODE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_RUNMODE_CHANGED)\n"));
			int32 mode;
			if (message->FindInt32("run_mode", &mode) == B_OK)
			{
				_changeRunModeForSelection(static_cast<uint32>(mode));
			}
			break;
		}
		case M_LAYOUT_CHANGED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_LAYOUT_CHANGED)\n"));
			layout_t layout;
			if (message->FindInt32("layout", (int32*)&layout) == B_OK)
			{
				if (layout != m_layout)
				{
					layoutChanged(layout);
					updateDataRect();
					Invalidate();
				}
			}
			break;
		}
		case M_NODE_START_TIME_SOURCE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_START_TIME_SOURCE)\n"));
			int32 id;
			if(message->FindInt32("nodeID", &id) < B_OK)
				break;
			NodeRef* ref;
			if(manager->getNodeRef(id, &ref) < B_OK)
				break;
			
			bigtime_t when = system_time();
			status_t err = manager->roster->StartTimeSource(ref->node(), when);
			if(err < B_OK) {
				PRINT((
					"! StartTimeSource(%ld): '%s'\n",
					ref->id(), strerror(err)));
			}
			break;
		}
		case M_NODE_STOP_TIME_SOURCE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_STOP_TIME_SOURCE)\n"));
			int32 id;
			if(message->FindInt32("nodeID", &id) < B_OK)
				break;
			NodeRef* ref;
			if(manager->getNodeRef(id, &ref) < B_OK)
				break;
			
			bigtime_t when = system_time();
			status_t err = manager->roster->StopTimeSource(ref->node(), when);
			if(err < B_OK) {
				PRINT((
					"! StopTimeSource(%ld): '%s'\n",
					ref->id(), strerror(err)));
			}
			break;
		}
		case M_NODE_TWEAK_PARAMETERS: {
			D_MESSAGE((" -> M_NODE_TWEAK_PARAMETERS\n"));
			_openParameterWindowsForSelection();
			break;
		}
		case M_NODE_START_CONTROL_PANEL: {
			D_MESSAGE((" -> M_NODE_START_CONTROL_PANEL\n"));
			_startControlPanelsForSelection();
			break;
		}
		case M_GROUP_SET_LOCKED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_GROUP_SET_LOCKED)\n"));
			int32 groupID;
			if(message->FindInt32("groupID", &groupID) < B_OK)
				break;
			bool locked;
			if(message->FindBool("locked", &locked) < B_OK)
				break;
			NodeGroup* group;
			if(manager->findGroup(groupID, &group) < B_OK)
				break;
			uint32 f = locked ?
				group->groupFlags() | NodeGroup::GROUP_LOCKED :
				group->groupFlags() & ~NodeGroup::GROUP_LOCKED;
			group->setGroupFlags(f);
			break;
		}
		case M_BROADCAST_SELECTION: {
			D_MESSAGE((" -> M_BROADCAST_SELECTION\n"));
			_broadcastSelection();
			break;
		}
		case InfoWindowManager::M_INFO_WINDOW_REQUESTED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(InfoView::M_INFO_WINDOW_REQUESTED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("input", &type, &count) == B_OK)
			{
				for (int32 i = 0; i < count; i++)
				{
					media_input input;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("input", B_RAW_TYPE, i, &data, &dataSize) == B_OK)
					{
						input = *reinterpret_cast<const media_input *>(data);
						InfoWindowManager *manager = InfoWindowManager::Instance();
						if (manager && manager->Lock()) {
							manager->openWindowFor(input);
							manager->Unlock();
						}
					}
				}
			}
			else if (message->GetInfo("output", &type, &count) == B_OK)
			{
				for (int32 i = 0; i < count; i++)
				{
					media_output output;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("output", B_RAW_TYPE, i, &data, &dataSize) == B_OK)
					{
						output = *reinterpret_cast<const media_output *>(data);
						InfoWindowManager *manager = InfoWindowManager::Instance();
						if (manager && manager->Lock()) {
							manager->openWindowFor(output);
							manager->Unlock();
						}
					}
				}
			}
			else
			{
				_openInfoWindowsForSelection();
			}
			break;
		}
		case NodeManager::M_RELEASED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(NodeManager::M_RELEASED)\n"));
			remove_observer(this, manager);
			const_cast<RouteAppNodeManager*&>(manager) = 0;	
			// +++++ disable view!
			break;
		}			
		case NodeRef::M_RELEASED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(NodeRef::M_RELEASED)\n"));
			// only relevant on shutdown; do nothing
			break;
		}
		default:
		{
			DiagramView::MessageReceived(message);
		}
	}
}
void MediaRoutingView::messageDropped(
	BPoint point,
	BMessage *message)
{
	D_METHOD(("MediaRoutingView::messageDropped()\n"));

	switch (message->what)
	{
		case DormantNodeView::M_INSTANTIATE_NODE:
		{
			D_MESSAGE(("MediaRoutingView::messageDropped(DormantNodeView::M_INSTANTIATE_NODE)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("which", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++)
				{
					dormant_node_info info;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("which", B_RAW_TYPE, &data, &dataSize) == B_OK)
					{
						memcpy(reinterpret_cast<void *>(&info), data, dataSize);
						NodeRef* droppedNode;
						status_t error;
						error = manager->instantiate(info, &droppedNode);
						if (!error)
						{
							m_lastDroppedNode = droppedNode->id();
							BPoint dropPoint, dropOffset;
							dropPoint = message->DropPoint(&dropOffset);
							m_lastDropPoint = align(ConvertFromScreen(dropPoint - dropOffset));
						}
						else
						{
							BString s;
							s << "Could not instantiate '" << info.name << "'";
							showErrorMessage(s, error);
						}
					}	
				}
			}
			break;
		}
		case B_SIMPLE_DATA:
		{
			D_MESSAGE(("MediaRoutingView::messageDropped(B_SIMPLE_DATA)\n"));
			entry_ref fileRef;
			if (message->FindRef("refs", &fileRef) == B_OK)
			{
				_checkDroppedFile(&fileRef, ConvertFromScreen(message->DropPoint()));
			}
			break;
		}
		case B_PASTE:
		{
			D_MESSAGE(("MediaRoutingView::messageDropped(B_PASTE)\n"));
			ssize_t size;
			const rgb_color *color; // [e.moon 21nov99] fixed const error
			if (message->FindData("RGBColor", B_RGB_COLOR_TYPE, reinterpret_cast<const void **>(&color), &size) == B_OK)
			{
				_changeBackground(*color);
			}
			break;
		}
		default:
		{
			DiagramView::messageDropped(point, message);
		}
	}
}
void MediaRoutingView::_checkDroppedFile(
	entry_ref *ref,
	BPoint dropPoint)
{
	D_METHOD(("MediaRoutingView::_checkDroppedFile()\n"));

	// [cell 26apr00] traverse links
	BEntry entry(ref, true);
	entry.GetRef(ref);

	BNode node(ref);
	if (node.InitCheck() == B_OK)
	{
		BNodeInfo nodeInfo(&node);
		if (nodeInfo.InitCheck() == B_OK)
		{
			char mimeString[B_MIME_TYPE_LENGTH];
			if (nodeInfo.GetType(mimeString) == B_OK)
			{
				BMimeType mimeType(mimeString);
				BMimeType superType;
				
				// [e.moon 22dec99] handle dropped node-set files
				if(mimeType == RouteApp::s_nodeSetType) {
					BMessage m(B_REFS_RECEIVED);
					m.AddRef("refs", ref);
					be_app_messenger.SendMessage(&m);
				}
				else if (mimeType.GetSupertype(&superType) == B_OK)
				{
					if (superType == "image")
					{
						_changeBackground(ref);
					}
					else if ((superType == "audio") || (superType == "video"))
					{
						NodeRef* droppedNode;
						status_t error;
						error = manager->instantiate(*ref, B_BUFFER_PRODUCER, &droppedNode);
						if (!error)
						{
							media_output encVideoOutput;
							if (droppedNode->findFreeOutput(&encVideoOutput, B_MEDIA_ENCODED_VIDEO) == B_OK)
							{
								droppedNode->setFlags(droppedNode->flags() | NodeRef::NO_POSITION_REPORTING);
							}
							m_lastDroppedNode = droppedNode->id();
							m_lastDropPoint = align(dropPoint);
						}
						else
						{
							char fileName[B_FILE_NAME_LENGTH]; 
							BEntry entry(ref);
							entry.GetName(fileName);
							BString s;
							s << "Could not load '" << fileName << "'";
							showErrorMessage(s, error);
						}
					}
				}
			}
		}
	}
}
Example #5
0
void RouteAppNodeManager::xmlImportChild(
	IPersistent*									child,
	ImportContext&								context) {

	status_t err;
	
	if(!strcmp(context.element(), _DORMANT_NODE_ELEMENT)) {
		DormantNodeIO* io = dynamic_cast<DormantNodeIO*>(child);
		ASSERT(io);
		
		NodeRef* newRef;
		err = io->instantiate(this, &newRef);
		if(err == B_OK) {
			// created node; add an entry to the set stored in the
			// ImportContext for later reference
			try {
				NodeSetIOContext& set = dynamic_cast<NodeSetIOContext&>(context);
				set.addNode(newRef->id(), io->nodeKey());
			}
			catch(bad_cast& e) {
				context.reportError("RouteAppNodeManager: expected a NodeSetIOContext\n");
			}
		}
		else {
			D_SETTINGS((
				"!!! RouteAppNodeManager::xmlImportChild():\n"
				"    DormantNodeIO::instantiate() failed:\n"
				"    '%s'\n",
				strerror(err)));
		}
	}
	else if(!strcmp(context.element(), _CONNECTION_ELEMENT)) {
		ConnectionIO* io = dynamic_cast<ConnectionIO*>(child);
		ASSERT(io);
		
		// instantiate the connection
		Connection con;
		err = io->instantiate(
			this,
			dynamic_cast<NodeSetIOContext*>(&context),
			&con);
		if(err < B_OK) {
			D_SETTINGS((
				"!!! ConnectionIO::instantiate() failed:\n"
				"    '%s'\n", strerror(err)));
		}
		
		// +++++ group magic?

	}
	else if(!strcmp(context.element(), _NODE_GROUP_ELEMENT)) {
		// +++++
	}
	else if(
		context.parentElement() &&
		!strcmp(context.parentElement(), _UI_STATE_ELEMENT)) {
	
		// expect a nested message
		MessageIO* io = dynamic_cast<MessageIO*>(child);
		if(!io) {
			BString err;
			err <<
				"RouteAppNodeManager: unexpected child '" <<
				context.element() << "'\n";
			context.reportError(err.String());
		}
		
		// hand it off via the extended context object
		try {
			NodeSetIOContext& set = dynamic_cast<NodeSetIOContext&>(context);
			set.importUIState(io->message());
		}
		catch(bad_cast& e) {
			context.reportError("RouteAppNodeManager: expected a NodeSetIOContext\n");
		}
	}
	
}