Logo Search packages:      
Sourcecode: ardour version File versions  Download package

void ImageFrameSocketHandler::handle_insert_imageframe_view ( const char *  msg  )  [private]

Handle the insertion of a new ImageFrameItem

Parameters:
msg the received message

Definition at line 1296 of file imageframe_socket_handler.cc.

References ImageFrameTimeAxisGroup::add_imageframe_item(), sigc::bind(), sigc::signal7< T_return, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7, T_accumulator >::connect(), TimeAxisViewItem::DurationChanged, ImageFrameTimeAxis::get_image_display_height(), get_message_part(), ImageFrameTimeAxisView::get_named_imageframe_group(), ImageFrameTimeAxis::get_view(), TimeAxisViewItem::ItemRemoved, sigc::mem_fun(), TimeAxisViewItem::PositionChanged, read_message(), send_imageframe_view_duration_change(), send_imageframe_view_position_change(), send_imageframe_view_removed(), send_message(), send_return_failure(), send_return_success(), theArdourToCompositorSocket, and thePublicEditor.

Referenced by handle_insert_message().

{
      int position = 4 ; // message type chars
      
      // get the ImageFrameTrack name size
      int track_name_size = atoi(get_message_part(position,3,msg).c_str()) ;
      position += 3 ;
      
      // get the ImageFrameTrack Name
      std::string imageframe_track_name = get_message_part(position,track_name_size,msg) ;
      position += track_name_size ;
      
      // get the scene name size
      int scene_size = atoi(get_message_part(position,3,msg).c_str()) ;
      position += 3 ;
      
      // get the scene Name
      std::string scene_name = get_message_part(position,scene_size,msg) ;
      position += scene_size ;
      
      // get the image frame_id size
      int image_id_size = atoi(get_message_part(position,3,msg).c_str()) ;
      position += 3 ;
      
      // get the image frame_id
      std::string image_id = get_message_part(position,image_id_size,msg) ;
      position += image_id_size ;
      
      // get the start frame value
      nframes_t start = strtoul((get_message_part(position,10,msg).c_str()),0,10) ;
      position += 10 ;
      
      // get the duration value
      nframes_t duration = strtoul((get_message_part(position,10,msg).c_str()),0,10) ;
      position += 10 ;

      //get the named time axis view we about to add an image to
      TimeAxisView* tav = thePublicEditor.get_named_time_axis(imageframe_track_name) ;
      ImageFrameTimeAxis* ifta = 0 ;
      
      if(tav)
      {
            ifta = dynamic_cast<ImageFrameTimeAxis*>(tav) ;
      }
      
      if(!ifta)
      {
            std::string errmsg("No Parent Image Track Found: ") ;
            errmsg.append(imageframe_track_name) ;
            send_return_failure(errmsg) ;
            
            // dont really like all these returns mid-way
            // but this is goinf to get awfully if..then nested if not
            return ;
      }
      
      // check the parent group exists
      ImageFrameTimeAxisGroup* iftag = ifta->get_view()->get_named_imageframe_group(scene_name) ;
      if(!iftag)
      {
            std::string errmsg("No Image Frame Group Found: ") ;
            errmsg.append(scene_name) ;
            send_return_failure(errmsg) ;
            return ;
      }
      
      // ok, so we have the parent group and track, now we need dome image data
      
      
      //
      // request the image data from the image compositor
      //
      
      // ctreate a message buffer
      std::ostringstream reqBuffer ;
      reqBuffer << std::setfill('0') ;
      
      // add the msg type
      reqBuffer << REQUEST_DATA << IMAGE_RGB_DATA ;
      
      // add the image track and size
      reqBuffer << std::setw(ardourvis::TEXT_SIZE_CHARS) << track_name_size ;
      reqBuffer << imageframe_track_name ;
      
      // add the scene id and size
      reqBuffer << std::setw(ardourvis::TEXT_SIZE_CHARS) << scene_size ;
      reqBuffer << scene_name ;
      
      // add the image id and size
      reqBuffer << std::setw(ardourvis::TEXT_SIZE_CHARS) << image_id_size ;
      reqBuffer << image_id ;
      
      // add the preferred image height
      reqBuffer << std::setw(ardourvis::TEXT_SIZE_CHARS) << ifta->get_image_display_height() ;
      
      // send the request message
      send_message(reqBuffer.str()) ;


      // read the reply, the inital image data message
      // this gives us the image dimensions and the expected size of the image data
      // msg type(4) + image width(3) + height(3) + num channels(3) + size of the image data (32)
      std::string init_image_data_msg ;
      read_message(init_image_data_msg) ;
      int init_msg_pos = 4 ;
      
      int imgWidth    = atoi(init_image_data_msg.substr(init_msg_pos, ardourvis::IMAGE_SIZE_CHARS).c_str()) ;
      init_msg_pos += ardourvis::IMAGE_SIZE_CHARS ;
      int imgHeight    = atoi(init_image_data_msg.substr(init_msg_pos, ardourvis::IMAGE_SIZE_CHARS).c_str()) ;
      init_msg_pos += ardourvis::IMAGE_SIZE_CHARS ;
      int imgChannels    = atoi(init_image_data_msg.substr(init_msg_pos, ardourvis::IMAGE_SIZE_CHARS).c_str()) ;
      init_msg_pos += ardourvis::IMAGE_SIZE_CHARS ; 
      int imgSize = atoi(init_image_data_msg.substr(init_msg_pos, ardourvis::IMAGE_DATA_MESSAGE_SIZE_CHARS).c_str()) ;

      // send a success msg
      // we need to do this to keep things moving
      send_return_success() ;

      // create our image rgb buffer, this holds the image data we receive
      unsigned char* rgb_img_buf = new unsigned char[imgSize] ;

      int retcode = ::recv(theArdourToCompositorSocket, rgb_img_buf, imgSize, MSG_WAITALL) ;

      if(retcode != imgSize)
      {
            delete [] rgb_img_buf ;
            send_return_failure("Could not create new Image Frame View : image data sizes did not match") ;
      }
      else
      {
            ImageFrameView* ifv = iftag->add_imageframe_item(image_id, start, duration, rgb_img_buf, (uint32_t)imgWidth, (uint32_t)imgHeight, (uint32_t)imgChannels, this) ;
            if(ifv)
            {
                  ifv->PositionChanged.connect(sigc::bind(sigc::mem_fun(*this, &ImageFrameSocketHandler::send_imageframe_view_position_change), ifv)) ;
                  ifv->DurationChanged.connect(sigc::bind(sigc::mem_fun(*this, &ImageFrameSocketHandler::send_imageframe_view_duration_change), ifv)) ;
                  ifv->ItemRemoved.connect(sigc::bind(sigc::mem_fun(*this, &ImageFrameSocketHandler::send_imageframe_view_removed), ifv)) ;
            
                  send_return_success() ;
            }
            else
            {
                  //addition failed. assume duplicate item_id
                  send_return_failure("Could not create new Image Frame View") ;
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index