Exemplo n.º 1
0
void MacroCommand::readProperties(boost::property_tree::wptree& pt)
{
    AbstractCommand::readProperties(pt);

    setMacro(QString::fromStdWString(pt.get(L"macro", TriCaster::DEFAULT_MACRO.toStdWString())));
    setTriggerOnNext(pt.get(L"triggeronnext", TriCaster::DEFAULT_TRIGGER_ON_NEXT));
}
Exemplo n.º 2
0
void MacroManager::trySaveMacro(Macro* m, QString curProg, int curMKey, int curGKey)
{
  if(m->curEvent > 0)
  {
    //Save previous macro
    writeDbg(tr("Add macro for: ") + curProg + tr(" at M") + QString::number(curMKey) + tr(",G") + QString::number(curGKey) + tr(" with ") + QString::number(m->curEvent) + tr(" events"));
    setMacro(curMKey, curGKey, *m);
    *m = Macro();
  }
}
Exemplo n.º 3
0
int caInclude::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = getMacro(); break;
        case 1: *reinterpret_cast< QString*>(_v) = getFileName(); break;
        case 2: *reinterpret_cast< Visibility*>(_v) = getVisibility(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getVisibilityCalc(); break;
        case 4: *reinterpret_cast< QString*>(_v) = getChannelA(); break;
        case 5: *reinterpret_cast< QString*>(_v) = getChannelB(); break;
        case 6: *reinterpret_cast< QString*>(_v) = getChannelC(); break;
        case 7: *reinterpret_cast< QString*>(_v) = getChannelD(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setMacro(*reinterpret_cast< QString*>(_v)); break;
        case 1: setFileName(*reinterpret_cast< QString*>(_v)); break;
        case 2: setVisibility(*reinterpret_cast< Visibility*>(_v)); break;
        case 3: setVisibilityCalc(*reinterpret_cast< QString*>(_v)); break;
        case 4: setChannelA(*reinterpret_cast< QString*>(_v)); break;
        case 5: setChannelB(*reinterpret_cast< QString*>(_v)); break;
        case 6: setChannelC(*reinterpret_cast< QString*>(_v)); break;
        case 7: setChannelD(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 4
0
void MacroManager::load()
{
	QDir dir(savePath);
	if(!dir.exists())
		return; //no need to bother trying to load

	QFile data(savePath + "/qtmacrocodes.cfg");
	if(!data.exists())
		return;

	if(data.open(QFile::ReadOnly))
	{
		QTextStream in(&data);
		QString line;
		int i=0, eventNo=0;
		QString curProg;
		int curMKey = 0;
		int curGKey = 0;
		Macro m;

		while((line = in.readLine()) != NULL)
		{
			if(i==0) //this is version line. Isn't needed in first version
			{
				i++;
				continue;
			}

			if(line.left(2) == "#p")
			{
				//Prog line
				curProg = line.right(line.length()-2);
			}
			else if(line.left(2) == "#m")
			{
				//Mkey line
				curMKey = line.right(1).toInt(NULL);
			}
			else if(line.left(2) == "#g")
			{
				if(m.curEvent > 0)
				{
					//Save previous macro
					setCurActiveId(&curProg);
					m.curEvent = eventNo;
					setMacro(curMKey, curGKey, &m);
				}
				//A GKey line
				curGKey = line.right(2).toInt(NULL);
				eventNo = 0; //reset counter
			}
			else if(line.contains("=", Qt::CaseSensitive))
			{
				//Event line
				QStringList eventInfo = line.split("=");
				if(eventInfo.count() != 2)
					continue;
				
				m.addEvent(eventInfo.at(0).toInt(NULL), (bool)eventInfo.at(1).toInt(NULL));
			}
		}
	}
}
Exemplo n.º 5
0
bool Bass::executeInstruction(Instruction& i) {
  activeInstruction = &i;
  string s = i.statement;
  evaluateDefines(s);

  if(s.match("macro ?*(*) {") || s.match("global macro ?*(*) {")) {
    bool local = s.beginsWith("global ") == false;
    s.ltrim<1>("global ");
    s.trim<1>("macro ", ") {");
    lstring p = s.split<1>("(");
    bool scoped = p(0).beginsWith("scope ");
    p(0).ltrim<1>("scope ");
    lstring a = p(1).empty() ? lstring{} : p(1).qsplit(",").strip();
    setMacro(p(0), a, ip, scoped, local);
    ip = i.ip;
    return true;
  }

  if(s.match("define ?*(*)") || s.match("global define ?*(*)")) {
    bool local = s.beginsWith("global ") == false;
    s.ltrim<1>("global ");
    lstring p = s.trim<1>("define ", ")").split<1>("(");
    setDefine(p(0), p(1), local);
    return true;
  }

  if(s.match("evaluate ?*(*)") || s.match("global evaluate ?*(*)")) {
    bool local = s.beginsWith("global ") == false;
    s.ltrim<1>("global ");
    lstring p = s.trim<1>("evaluate ", ")").split<1>("(");
    setDefine(p(0), evaluate(p(1)), local);
    return true;
  }

  if(s.match("variable ?*(*)") || s.match("global variable ?*(*)")) {
    bool local = s.beginsWith("global ") == false;
    s.ltrim<1>("global ");
    lstring p = s.trim<1>("variable ", ")").split<1>("(");
    setVariable(p(0), evaluate(p(1)), local);
    return true;
  }

  if(s.match("if ?* {")) {
    s.trim<1>("if ", " {").strip();
    bool match = evaluate(s, Evaluation::Strict);
    ifStack.append(match);
    if(match == false) {
      ip = i.ip;
    }
    return true;
  }

  if(s.match("} else if ?* {")) {
    if(ifStack.last()) {
      ip = i.ip;
    } else {
      s.trim<1>("} else if ", " {").strip();
      bool match = evaluate(s, Evaluation::Strict);
      ifStack.last() = match;
      if(match == false) {
        ip = i.ip;
      }
    }
    return true;
  }

  if(s.match("} else {")) {
    if(ifStack.last()) {
      ip = i.ip;
    } else {
      ifStack.last() = true;
    }
    return true;
  }

  if(s.match("} endif")) {
    ifStack.removeLast();
    return true;
  }

  if(s.match("while ?* {")) {
    s.trim<1>("while ", " {").strip();
    bool match = evaluate(s, Evaluation::Strict);
    if(match == false) ip = i.ip;
    return true;
  }

  if(s.match("} endwhile")) {
    ip = i.ip;
    return true;
  }

  if(s.match("?*(*)")) {
    lstring p = string{s}.rtrim<1>(")").split<1>("(");
    lstring a = p(1).empty() ? lstring{} : p(1).qsplit(",").strip();
    string name = {p(0), ":", a.size()};  //arity overloading
    if(auto macro = findMacro({name})) {
      struct Parameter {
        enum class Type : unsigned { Define, Variable } type;
        string name;
        string value;
      };

      vector<Parameter> parameters;
      for(unsigned n = 0; n < a.size(); n++) {
        lstring p = macro().parameters(n).split<1>(" ").strip();
        if(p.size() == 1) p.prepend("define");

        if(p(0) == "define") parameters.append({Parameter::Type::Define, p(1), a(n)});
        else if(p(0) == "string") parameters.append({Parameter::Type::Define, p(1), text(a(n))});
        else if(p(0) == "evaluate") parameters.append({Parameter::Type::Define, p(1), evaluate(a(n))});
        else if(p(0) == "variable") parameters.append({Parameter::Type::Variable, p(1), evaluate(a(n))});
        else error("unsupported parameter type: ", p(0));
      }

      StackFrame frame;
      stackFrame.append(frame);
      stackFrame.last().ip = ip;
      stackFrame.last().scoped = macro().scoped;

      if(macro().scoped) {
        scope.append(p(0));
      }

      setDefine("#", {"_", macroInvocationCounter++}, true);
      for(auto& parameter : parameters) {
        if(parameter.type == Parameter::Type::Define) setDefine(parameter.name, parameter.value, true);
        if(parameter.type == Parameter::Type::Variable) setVariable(parameter.name, integer(parameter.value), true);
      }

      ip = macro().ip;
      return true;
    }
  }

  if(s.match("} endmacro")) {
    ip = stackFrame.last().ip;
    if(stackFrame.last().scoped) scope.removeLast();
    stackFrame.removeLast();
    return true;
  }

  if(assemble(s)) {
    return true;
  }

  evaluate(s);
  return true;
}