Exemple #1
0
void Network::handleObjectLineMessage(const osc::ReceivedMessage& m,
                                      const IpEndpointName& remoteEndpoint)
{
  // Utility data structures
  char buffer[1024];
  osc::OutboundPacketStream ps(buffer, 1024);

  // Parse OSC message
  osc::Symbol uuid, padUuid;
  float startX, startY, endX, endY;
  m.ArgumentStream() >> uuid >> padUuid >> startX >> startY
                                        >> endX >> endY >> osc::EndMessage;
  std::cerr << uuid << ", " << padUuid << ", "
            << startX << ", " << startY << ", "
            << endX << ", " << endY << std::endl;

  // Check for known arc, add & broadcast if unknown
  WidgetMap* widgets = Widget::getAll();
  WidgetMap::iterator wit = widgets->find(std::string(uuid));
  if (wit == widgets->end()) {
    wit = m_orphans.find(std::string(uuid));
    if (wit == m_orphans.end()) {
      LineTrack* newLine = NULL;

      // Search for pad
      wit = widgets->find(std::string(padUuid));
      if (wit != widgets->end()) {
        Joint *endJoint = NULL, *startJoint = NULL;
        for (WidgetMap::iterator ptr = widgets->begin(); ptr != widgets->end(); ptr++) {
          Track *track = dynamic_cast<Track *>(ptr->second);
          if (track) {
            Joint *joint = track->getJoint1();
            if (!startJoint && joint && joint->hitTest(startX, startY))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endX, endY))
              endJoint = joint;

            joint = track->getJoint2();
            if (!startJoint && joint && joint->hitTest(startX, startY))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endX, endY))
              endJoint = joint;
          }
        }

        LineTrack* newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), startJoint, endJoint);
        newLine->setUuid(uuid);
        newLine->getLine()->setLineWidth(3);

        wit->second->addChild(newLine);
        widgets->insert(WidgetData(std::string(uuid), newLine));

        // Tell the world
        newLine->toOutboundPacketStream(ps);
        broadcast(ps);
      } else {// orphan if we don't know about its pad yet
        newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), NULL, NULL);
        newLine->setUuid(uuid);
        m_orphans.insert(WidgetData(std::string(padUuid), newLine));
      }
    }
  }
}
Exemple #2
0
void Network::handleObjectSpiralMessage(const osc::ReceivedMessage& m,
                                        const IpEndpointName& remoteEndpoint)
{
  // Utility data structures
  char buffer[1024];
  osc::OutboundPacketStream ps(buffer, 1024);

  // Parse OSC message
  osc::Symbol uuid, padUuid;
  float startAngle, startRadius, endAngle, endRadius;
  m.ArgumentStream() >> uuid >> padUuid >> startAngle >> startRadius
                                        >> endAngle >> endRadius >> osc::EndMessage;
  std::cerr << uuid << ", " << padUuid << ", "
            << startAngle << ", " << startRadius << ", "
            << endAngle << ", " << endRadius << std::endl;

  // Check for known arc, add & broadcast if unknown
  WidgetMap* widgets = Widget::getAll();
  WidgetMap::iterator wit = widgets->find(std::string(uuid));
  if (wit == widgets->end()) {
    wit = m_orphans.find(std::string(uuid));
    if (wit == m_orphans.end()) {
      SpiralTrack* newSpiral = NULL;

      // Search for pad
      wit = widgets->find(std::string(padUuid));
      if (wit != widgets->end()) {
        Point2D center = ((RoundPad*)wit->second)->getCenter();
        Point2D startPoint = Spiral::getPointFromRadius(center, startRadius, startAngle);
        Point2D endPoint = Spiral::getPointFromRadius(center, endRadius, endAngle);
        Joint *endJoint = NULL, *startJoint = NULL;
        std::vector<Widget*>* children = wit->second->getChildren();

        for (int i = children->size() - 1; i >= 0; i --) {
          Track *track = dynamic_cast<Track *>(children->at(i));
          if (track) {
            Joint *joint = track->getJoint1();
            if (!startJoint && joint && joint->hitTest(startPoint.x, startPoint.y))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endPoint.x, endPoint.y))
              endJoint = joint;

            joint = track->getJoint2();
            if (!startJoint && joint && joint->hitTest(startPoint.x, startPoint.y))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endPoint.x, endPoint.y))
              endJoint = joint;
          }
        }

        newSpiral = new SpiralTrack(center, startAngle, startRadius,
                                    endAngle, endRadius, startJoint, endJoint);
        newSpiral->setUuid(uuid);
        newSpiral->getSpiral()->setLineWidth(3);
        newSpiral->getJoint1()->setParentRoundPad(((RoundPad*)wit->second));
        newSpiral->getJoint2()->setParentRoundPad(((RoundPad*)wit->second));

        wit->second->addChild(newSpiral);
        widgets->insert(WidgetData(std::string(uuid), newSpiral));

        // Tell the world
        newSpiral->toOutboundPacketStream(ps);
        broadcast(ps);
      } else {// orphan if we don't know about its pad yet
        newSpiral = new SpiralTrack(Point2D(0, 0), startAngle, startRadius,
                                    endAngle, endRadius, NULL, NULL);
        newSpiral->setUuid(uuid);
        m_orphans.insert(WidgetData(std::string(padUuid), newSpiral));
      }
    }
  }
}