Пример #1
0
void VampPlugin::applyParameters(MarSystem *system)
{
  map<string, float>::const_iterator it;
  for (it = m_params.begin(); it != m_params.end(); ++it)
  {
    const string & id = it->first;
    float value = it->second;

    MarControlPtr control = system->control(id);

    if (control.isInvalid())
    {
      cerr << "Invalid parameter id: " << id << endl;
      continue;
    }

    if (control->hasType<mrs_real>())
    {
      control->setValue((mrs_real) value);
    }
    else if (control->hasType<mrs_natural>())
    {
      control->setValue((mrs_natural) value);
    }
    else
    {
      cerr << "Invalid type for parameter id: " << id << endl;
    }
  }
}
Пример #2
0
void RealvecWidget::refreshFromControl()
{
  Q_ASSERT(m_system);
  Q_ASSERT(!m_path.isEmpty());

  MarControlPtr control = m_system->getControl( m_path.toStdString() );
  if (control.isInvalid()) {
    qWarning() << "RealvecWidget: invalid control path:" << m_path;
    clearPlot();
    return;
  }

  if (control->getType() != "mrs_realvec") {
    //qWarning() << "RealvecWidget: control type not 'mrs_realvec':" << m_control_path;
    clearPlot();
    return;
  }

  const realvec & data = control->to<mrs_realvec>();
  m_table->setData(data);

  m_data = data;
  if (m_plot)
    m_plot->setData(&m_data);
}
Пример #3
0
static int apply_controls( MarSystem *system,
                           const vector<pair<string,string>> & controls )
{
  for( const auto & mapping : controls )
  {
    const string & control_path = mapping.first;
    const string & control_value_text = mapping.second;

    MarControlPtr control = system->remoteControl(control_path);
    if (control.isInvalid())
    {
      MRSERR("Can not set control - invalid path: " << control_path);
      return 1;
    }
    int err = set_control(control, control_value_text);
    if (err)
    {
      MRSERR("Can not set control - invalid value: "
             << control_path << " = " << control_value_text);
      return err;
    }
  }

  return 0;
}
Пример #4
0
void process_message( MarSystem * root_system, const osc::ReceivedMessage& message )
{
  const char * path = message.AddressPattern();
  if (path[0] == '/') ++path;

  // FIXME: Constructing std::string is not real-time-safe.
  MarControlPtr control = find_control(root_system, path);
  if (control.isInvalid())
  {
    MRSWARN("OSC receiver: no control for path: " << path);
    return;
  }

  try
  {
    osc::ReceivedMessage::const_iterator it = message.ArgumentsBegin();
    if (it == message.ArgumentsEnd())
      throw std::runtime_error("OSC receiver: Message has no arguments.");

    char tag = it->TypeTag();
    switch(tag)
    {
    case osc::TRUE_TYPE_TAG:
    case osc::FALSE_TYPE_TAG:
      control->setValue(it->AsBoolUnchecked());
      break;
    case osc::INT32_TYPE_TAG:
      control->setValue(it->AsInt32Unchecked());
      break;
    case osc::FLOAT_TYPE_TAG:
      control->setValue((mrs_real) it->AsFloatUnchecked());
      break;
    case osc::DOUBLE_TYPE_TAG:
      control->setValue((mrs_real) it->AsDoubleUnchecked());
      break;
    case osc::STRING_TYPE_TAG:
      control->setValue(it->AsStringUnchecked());
      break;
    default:
      throw std::runtime_error("OSC receiver: Unsupported message argument type.");
    }
  }
  catch ( std::exception & e )
  {
    MRSWARN("OSC receiver: error while parsing message: " << e.what());
  }
}
Пример #5
0
void RunnerThread::process_requests()
{
  Event *event;
  while( m_shared->request_queue.pop(event) )
  {
    //cout << "MarSystemThread: popped event: type=" << event->type << endl;
    switch (event->type) {
    case SetControl:
    {
      SetControlEvent* request = static_cast<SetControlEvent*>(event);
      //cout << "MarSystemThread: setting control: " << request->control->getName() << endl;
      set_control_value( request->control, request->value );
      break;
    }
    case SetControlValue:
    {
      SetControlValueEvent* request = static_cast<SetControlValueEvent*>(event);
      //cout << "MarSystemThread: setting control value: " << request->path << endl;
      MarControlPtr control = m_system->getControl(request->path);
      if (control.isInvalid()) {
        MRSERR("Marsyas::Thread::System:: Can not set control - invalid path: " << request->path);
      } else
        set_control_value(control, request->value );
      break;
    }
    case SetControls:
    {
      SetControlsEvent *request = static_cast<SetControlsEvent*>(event);
for( const auto & mapping : request->control_values )
      {
        const bool do_not_update = false;
        //cout << "MarSystemThread: setting staged control: " << mapping.first->getName() << endl;
        // FIXME: evil const_cast:
        MarControlPtr & settable_control = const_cast<MarControlPtr &>(mapping.first);
        set_control_value(settable_control, mapping.second, do_not_update);
      }
      m_system->update();
      break;
    }
    default:
      MRSERR("Marsyas::Thread::System:: unsupported event type: " << event->type);
    }

    event->setProcessed();
  }
}
Пример #6
0
int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    cerr << "Usage: <input file> <output file>" << endl;
    return 1;
  }

  char *input_filename = argv[1];
  char *output_filename = argv[2];

  detector::registerScripts();

  ScriptTranslator translator;
  MarSystem *system = translator.translateRegistered("detector.mrs");
  if (!system)
  {
    cerr << "Failure loading script!" << endl;
    return 1;
  }

  MarControlPtr input_control = system->control("input");
  MarControlPtr output_control = system->control("output");
  MarControlPtr done_control = system->control("done");

  if ( input_control.isInvalid() ||
       output_control.isInvalid() ||
       done_control.isInvalid() )
  {
    cerr << "Failure: Invalid script!" << endl;
    delete system;
    return 1;
  }

  input_control->setValue(string(input_filename));
  //output_control->setValue(string("features.out"));

  mrs_real sample_rate = system->remoteControl("sndfile/osrate")->to<mrs_real>();
  mrs_natural block_size = system->remoteControl("sndfile/onSamples")->to<mrs_natural>();
  mrs_real block_duration = block_size / sample_rate;

  MarControlPtr output = system->getControl("mrs_realvec/processedData");
  MarControlPtr confidence_ctl = system->remoteControl("onsets/confidence");
  assert(!output.isInvalid());
  assert(!confidence_ctl.isInvalid());

  MarSystem *rms_sys = system->remoteSystem("rms");
  assert(rms_sys);
  MarControlPtr rms_out = rms_sys->getControl("mrs_real/value");
  assert(!rms_out.isInvalid());

  std::vector<onset> onsets;
  int block = 0;
  const int block_offset = 5;

  while(!done_control->to<bool>())
  {
    system->tick();

    const realvec & data = output->to<realvec>();
    assert(data.getSize() == 2);

    mrs_real confidence = confidence_ctl->to<mrs_real>();

    if (!(data(0) > 0.0) || confidence < 10.0 / 100.0)
    {
      ++block;
      continue;
    }

    mrs_real centroid = data(1);

    double rms = rms_out->to<mrs_real>();

    onset o;

    o.time = (block - block_offset + 0.5) * block_duration;

    if (centroid < 0.04)
      o.type = 0;
    else if (centroid < 0.3)
      o.type = 1;
    else
      o.type = 2;

    o.strength = rms;

    onsets.push_back(o);

    ++block;
  }

  string separator(",");

  ofstream out_file(output_filename);
  if (!out_file.is_open())
  {
    cerr << "Failed to open output file for writing: " << output_filename << endl;
    return 1;
  }

  for (int i = 0; i < onsets.size(); ++i)
  {
    out_file << onsets[i].time << separator
             << onsets[i].type << separator
             << onsets[i].strength
             << endl;
  }

  cout << "Done." << endl;

  return 0;
}
Пример #7
0
	bool
	MarControl::linkTo(MarControlPtr ctrl, bool update)
	{
		if (ctrl.isInvalid())
		{
			ostringstream oss;
			oss << "MarControl::linkTo() - Linking to an invalid control ";
			oss << "(" << ctrl->cname_ << " with " << cname_ << ").";
			MRSWARN(oss.str());
			return false;
		}

		//check if these controls are already linked
		//(i.e. they own the same MarControlValue) 
		if(value_ == ctrl->value_)
		{
			return true;//already linked! :-)
		}
	
		if (ctrl->value_->type_ != value_->type_)
		{
			ostringstream oss;
			oss << "MarControl::linkTo() - Linking controls of different types ";
			oss << "(" << ctrl->cname_ << " with " << cname_ << ").";
			MRSWARN(oss.str());
			return false;
		}

		//unlink this control (but keeping all links to it) 
		//before linking it again to the passed control
		this->unlinkFromTarget();

		//store a pointer to the (soon to be old) MarControlValue object,
		//so we can later delete it from memory
		MarControlValue* oldvalue = value_;
		//and get a pointer to the new value
		MarControlValue* newvalue = ctrl->value_;

		//get all the links of our current MarControlValue so we can also
		//re-link them to the passed ctrl
		vector<pair<MarControl*, MarControl*> >::iterator lit;
		for(lit=oldvalue->links_.begin(); lit!=oldvalue->links_.end(); ++lit)
		{
			//make each linked control now point to the "passed" MarControlValue
			lit->first->value_ = newvalue;

			// check if this is the root link
			if(lit->first == lit->second)
			{
				//make it "link to" the passed control
				newvalue->links_.push_back(pair<MarControl*, MarControl*>(lit->first, ctrl())); 
			}
			else //if not a root link, just copy the table entry unchanged into the new MarControlValue
				newvalue->links_.push_back(*lit); 
		}

		//old MarControlValue can and should now be safely deleted from memory
		delete oldvalue;

		//check if it's needed to call update()
		if(update)
			value_->callMarSystemsUpdate();//newvalue->callMarSystemsUpdate();

		return true;
	}