bool STObject::clearFlag (uint32 f)
{
    STUInt32* t = dynamic_cast<STUInt32*> (getPField (sfFlags));

    if (!t)
        return false;

    t->setValue (t->getValue () & ~f);
    return true;
}
Пример #2
0
bool STObject::setFlag (std::uint32_t f)
{
    STUInt32* t = dynamic_cast<STUInt32*> (getPField (sfFlags, true));

    if (!t)
        return false;

    t->setValue (t->getValue () | f);
    return true;
}
void STObject::setFieldVL (SField::ref field, Blob const& v)
{
    SerializedType* rf = getPField (field, true);

    if (!rf) throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field);

    STVariableLength* cf = dynamic_cast<STVariableLength*> (rf);

    if (!cf) throw std::runtime_error ("Wrong field type");

    cf->setValue (v);
}
void STObject::setFieldAccount (SField::ref field, const uint160& v)
{
    SerializedType* rf = getPField (field, true);

    if (!rf) throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field);

    STAccount* cf = dynamic_cast<STAccount*> (rf);

    if (!cf) throw std::runtime_error ("Wrong field type");

    cf->setValueH160 (v);
}
void STObject::setFieldU8 (SField::ref field, unsigned char v)
{
    SerializedType* rf = getPField (field, true);

    if (!rf) throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field);

    STUInt8* cf = dynamic_cast<STUInt8*> (rf);

    if (!cf) throw std::runtime_error ("Wrong field type");

    cf->setValue (v);
}
void STObject::setFieldPathSet (SField::ref field, const STPathSet& v)
{
    SerializedType* rf = getPField (field, true);

    if (!rf) throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field);

    STPathSet* cf = dynamic_cast<STPathSet*> (rf);

    if (!cf) throw std::runtime_error ("Wrong field type");

    (*cf) = v;
}
STObject& STObject::peekFieldObject (SField::ref field)
{
    SerializedType* rf = getPField (field, true);

    if (!rf)
        throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT)
        rf = makeFieldPresent (field);

    STObject* cf = dynamic_cast<STObject*> (rf);

    if (!cf)
        throw std::runtime_error ("Wrong field type");

    return *cf;
}
Пример #8
0
void STObject::setAccountID (SField const& field, AccountID const& v)
{
    STBase* rf = getPField (field, true);

    if (!rf)
        throw std::runtime_error ("Field not found");

    if (rf->getSType () == STI_NOTPRESENT)
        rf = makeFieldPresent (field);

    STAccount* cf = dynamic_cast<STAccount*> (rf);

    if (!cf)
        throw std::runtime_error ("Wrong field type");

    cf->setValueH160 (v);
}
Пример #9
0
int WAVY::setExpression()
{
	const PField &field = getPField(8);
	const char *fieldstr = field.stringValue(0.0);

	// copy expression string to <str>, stripping all white space
	const int len = strlen(fieldstr);
	char str[len + 1];
	char *p = str;
	for (int i = 0; i < len; i++) {
		const char c = fieldstr[i];
		if (!isspace(c))
			*p++ = c;
	}
	str[len] = 0;

	// Take care of some common simple cases first, since it's more efficient
	// to process them without using the fparser library.
	if (strcmp(str, "a") == 0)
		setCombineFunc(a);
	else if (strcmp(str, "b") == 0)
		setCombineFunc(b);
	else if (strcmp(str, "a+b") == 0)
		setCombineFunc(add);
	else if (strcmp(str, "a-b") == 0)
		setCombineFunc(subtract);
	else if (strcmp(str, "a*b") == 0)
		setCombineFunc(multiply);
	else {
		_fp = new FunctionParser();
		// use orig string so char offsets in err msg will be right
		int ret = _fp->Parse(fieldstr, "a,b");
		if (ret >= 0)
			return die("WAVY", "Parser error for expression \"%s\" at character "
			           "%d ('%c'): %s.",
			           fieldstr, ret, fieldstr[ret], _fp->ErrorMsg());
#ifdef OPTIMIZE_EXPRESSION
		_fp->Optimize();
#endif
	}

	return 0;
}
Пример #10
0
int PFSCHED::init(double p[], int n_args)
{
// about ths RTBUFSAMPS+1 nonsense:
// 	when a PFSCHED note finishes, it de-allocates the PFields associated
// 	with it.  This is generally not a problem (because the 'connected'
// 	instrument/note drawing from the PField only needs the PField for
// 	the duration specified in the PFSCHED note), but if the duration is
// 	less than one RTBUFSAMP then the PFSCHED note will finish and deallocate
// 	*before* the other instrument gets a chance to read through the
// 	'connected' PField.  Instead of rewriting a huge amount of the PField
// 	code to handle the ref counters, etc. I just make sure that the
// 	PFSCHED note will last at least one buffer longer than the time
// 	computed for the PField to be read.  Almost no additional load
// 	on the CPU, see the run() method below.

	if (rtsetoutput(p[0], p[1]+((double)(RTBUFSAMPS+1)/SR), this) == -1)
		return DONT_SCHEDULE;

	// if set_dq_flag is 1, then the dqflag of pfbusses[] will be set to
	// signal de-queuing at end of this duration/envelope
	if (n_args > 4) set_dq_flag = 1;
	else set_dq_flag = 0;

	pfbus = p[2];

	if (pfbus_is_connected[pfbus] != 1) {
		rterror("PFSCHED", "pfbus %d not connected", pfbus);
		return DONT_SCHEDULE;
	}


	pfbusses[pfbus].drawflag = 0; // the 'connected' note will read when == 1
//	pfbusses[pfbus].thepfield = &((*_pfields)[3]);
//	pfbusses[pfbus].thepfield = &(getPField(3)); // this is the PField to read
	PFSCHEDpfield = &(getPField(3)); // this is the PField to read

	// set the other fields in ::run in case multiple PFSCHEDs on one pfbus
	firsttime = 1;

	return nSamps();
}
Пример #11
0
FiltType FOLLOWBUTTER :: getFiltType(bool trystring)
{
   double index = (double) currentFrame() / nSamps();
   const PField &field = getPField(7);

   // must try int first, since a valid code cast to char * will crash strncmp
   int code = field.intValue(index) - 1;  // NB: user codes are 1-based
   if ((code < LowPass || code > BandReject) && trystring) {
      const char *str = field.stringValue(index);
      code = _string_to_filtcode(str);   // -1 if no match
      if (code != -1)
         filttype_was_string = true;
   }

   FiltType filttype;
   switch (code) {
      case 0: filttype = LowPass;      break;
      case 1: filttype = HighPass;     break;
      case 2: filttype = BandPass;     break;
      case 3: filttype = BandReject;   break;
      default: filttype = FiltInvalid; break;
   }
   return filttype;
}
Пример #12
0
OeqType MULTEQ :: getEQType(bool trystring, int pfindex)
{
   double index = (double) currentFrame() / nSamps();
   const PField &field = getPField(pfindex);

   // must try int first, since a valid code cast to char * will crash strncmp
   int code = field.intValue(index);
   if (trystring && (code < 0 || code > 4)) {
      const char *str = field.stringValue(index);
      code = _string_to_eqcode(str);   // -1 if no match
   }

   OeqType eqtype;
   switch (code) {
      case 0: eqtype = OeqLowPass;   break;
      case 1: eqtype = OeqHighPass;  break;
      case 2: eqtype = OeqLowShelf;  break;
      case 3: eqtype = OeqHighShelf; break;
      case 4: eqtype = OeqPeaking;   break;
      case 5: eqtype = OeqBandPassCSG; break;
      default: eqtype = OeqInvalid;  break;
   }
   return eqtype;
}
Пример #13
0
int SHAPE :: init(double p[], int n_args)
{
   nargs = n_args;
   float outskip = p[0];
   float inskip = p[1];
   float dur = p[2];
   amp = p[3];
   min_index = p[4];
   max_index = p[5];
   int ampnorm_genno = (int) p[6];
   inchan = n_args > 7 ? (int) p[7] : 0;             /* default is chan 0 */

   if (n_args < 7)
      return die("SHAPE", "Needs at least 7 arguments.");

   if (rtsetoutput(outskip, dur, this) == -1)
      return DONT_SCHEDULE;
   if (rtsetinput(inskip, this) == -1)
      return DONT_SCHEDULE;

   if (inchan >= inputChannels())
      return die("SHAPE", "You asked for channel %d of a %d-channel file.",
                                                   inchan, inputChannels());

   if (max_index < min_index)
      return die("SHAPE",
                 "Max. distortion index must not be less than min. index.");

   double *function = floc(1);
   if (function) {
      int len = fsize(1);
      amp_table = new TableL(SR, dur, function, len);
   }

   function = NULL;
   int tablelen = 0;
   if (n_args > 9) {    // handle table coming in as optional p9 TablePField
      function = (double *) getPFieldTable(9, &tablelen);
   }
   if (function == NULL) {
      function = floc(2);
      if (function == NULL)
         return die("SHAPE", "Either use the transfer function pfield (p9) "
                    "or make an old-style gen function in slot 2.");
      tablelen = fsize(2);
   }
   shaper = new WavShape();
   shaper->setTransferFunc(function, tablelen);

   function = NULL;
	if (n_args < 11) {		// no p10 guide PField, must use gen table
      function = floc(3);
      if (function) {
         int len = fsize(3);
         index_table = new TableL(SR, dur, function, len);
      }
      else
         rtcmix_advise("SHAPE", "Setting distortion index curve to all 1's.");
   }

   /* Construct the <ampnorm> WavShape object if (1) p6 is a TablePField, or
      (2) if p6 is non-zero, in which case use p6 as the gen slot for the
      amp norm function.  If p6 is zero, then don't construct <ampnorm>.
   */
   function = NULL;
   const PField &field = getPField(6);
   tablelen = field.values();
   function = (double *) field;
   if (function == NULL) {    // no table pfield
      if (ampnorm_genno > 0) {
         function = floc(ampnorm_genno);
         if (function == NULL)
            return die("SHAPE", "You specified table %d as the amplitude "
                    "normalization function, but you didn't create the table.",
                    ampnorm_genno);
         tablelen = fsize(ampnorm_genno);
      }
   }
   if (function) {
      ampnorm = new WavShape();
      ampnorm->setTransferFunc(function, tablelen);
   }

   dcblocker = new DCBlock();

   skip = (int) (SR / (float) resetval);

   return nSamps();
}