void
nest::music_message_in_proxy::calibrate()
{
  // only publish the port once,
  if ( !S_.published_ )
  {
    MUSIC::Setup* s = nest::Communicator::get_music_setup();
    if ( s == 0 )
      throw MUSICSimulationHasRun( get_name() );

    V_.MP_ = s->publishMessageInput( P_.port_name_ );

    if ( !V_.MP_->isConnected() )
      throw MUSICPortUnconnected( get_name(), P_.port_name_ );

    if ( !V_.MP_->hasWidth() )
      throw MUSICPortHasNoWidth( get_name(), P_.port_name_ );

    S_.port_width_ = V_.MP_->width();

    // MUSIC wants seconds, NEST has miliseconds
    double_t acceptable_latency = P_.acceptable_latency_ / 1000.0;

    V_.MP_->map( &B_.message_handler_, acceptable_latency );
    S_.published_ = true;

    std::string msg =
      String::compose( "Mapping MUSIC input port '%1' with width=%2 and acceptable latency=%3 ms.",
        P_.port_name_,
        S_.port_width_,
        P_.acceptable_latency_ );
    net_->message( SLIInterpreter::M_INFO, "music_message_in_proxy::calibrate()", msg.c_str() );
  }
}
void
MusicEventHandler::publish_port()
{
  if ( not published_ )
  {
    music_port_ =
      kernel().music_manager.get_music_setup()->publishEventInput( portname_ );

    // MUSIC wants seconds, NEST has miliseconds
    const double acceptable_latency_s = 0.001 * acceptable_latency_;

    if ( not music_port_->isConnected() )
    {
      throw MUSICPortUnconnected( "MusicEventHandler", portname_ );
    }

    if ( not music_port_->hasWidth() )
    {
      throw MUSICPortHasNoWidth( "MusicEventHandler", portname_ );
    }

    unsigned int music_port_width = music_port_->width();

    // check, if all mappings are within the valid range of port width
    // the maximum channel mapped - 1 == size of channelmap
    if ( channelmap_.size() > music_port_width )
    {
      throw MUSICChannelUnknown(
        "MusicEventHandler", portname_, channelmap_.size() - 1 );
    }

    // create the permutation index mapping
    music_perm_ind_ =
      new MUSIC::PermutationIndex( &indexmap_.front(), indexmap_.size() );
    // map the port
    if ( max_buffered_ >= 0 )
    {
      music_port_->map(
        music_perm_ind_, this, acceptable_latency_s, max_buffered_ );
    }
    else
    {
      music_port_->map( music_perm_ind_, this, acceptable_latency_s );
    }

    std::string msg = String::compose(
      "Mapping MUSIC input port '%1' with width=%2 , acceptable latency=%3 ms",
      portname_,
      music_port_width,
      acceptable_latency_ );
    if ( max_buffered_ > 0 )
    {
      msg += String::compose( " and max buffered=%1 ticks", max_buffered_ );
    }
    msg += ".";
    LOG( M_INFO, "MusicEventHandler::publish_port()", msg.c_str() );
  }
}
void
nest::music_cont_in_proxy::calibrate()
{
  // only publish the port once
  if ( !S_.published_ )
  {
    MUSIC::Setup* s = kernel().music_manager.get_music_setup();
    if ( s == 0 )
      throw MUSICSimulationHasRun( get_name() );

    V_.MP_ = s->publishContInput( P_.port_name_ );

    if ( !V_.MP_->isConnected() )
      throw MUSICPortUnconnected( get_name(), P_.port_name_ );

    if ( !V_.MP_->hasWidth() )
      throw MUSICPortHasNoWidth( get_name(), P_.port_name_ );

    S_.port_width_ = V_.MP_->width();

    B_.data_ = std::vector< double >( S_.port_width_ );
    MUSIC::ArrayData data_map( static_cast< void* >( &( B_.data_[ 0 ] ) ),
      MPI::DOUBLE,
      0,
      S_.port_width_ );

    V_.MP_->map( &data_map );
    S_.published_ = true;

    std::string msg =
      String::compose( "Mapping MUSIC input port '%1' with width=%2.",
        P_.port_name_,
        S_.port_width_ );
    LOG( M_INFO, "music_cont_in_proxy::calibrate()", msg.c_str() );
  }
}