/* This routine gets instrument parameters. npv is number of valid AUpvlist pairs */ void _af_instparam_get (AFfilehandle file, int instid, AUpvlist pvlist, int npv, bool forceLong) { int i, instno, j; if (!_af_filehandle_ok(file)) return; if ((instno = _af_handle_instrument_index_from_id(file, instid)) == -1) return; if (AUpvgetmaxitems(pvlist) < npv) npv = AUpvgetmaxitems(pvlist); for (i=0; i < npv; i++) { int param; int type; AUpvgetparam(pvlist, i, ¶m); if ((j = _af_instparam_index_from_id(file->fileFormat, param)) == -1) /* no parameter with that id; ignore */ continue; type = _af_units[file->fileFormat].instrumentParameters[j].type; /* forceLong is true when this routine called by afGetInstParamLong(). */ if (forceLong && type != AU_PVTYPE_LONG) { _af_error(AF_BAD_INSTPTYPE, "type of instrument parameter %d is not AU_PVTYPE_LONG", param); continue; } AUpvsetvaltype(pvlist, i, type); switch (type) { case AU_PVTYPE_LONG: AUpvsetval(pvlist, i, &file->instruments[instno].values[j].l); break; case AU_PVTYPE_DOUBLE: AUpvsetval(pvlist, i, &file->instruments[instno].values[j].d); break; case AU_PVTYPE_PTR: AUpvsetval(pvlist, i, &file->instruments[instno].values[j].v); break; default: _af_error(AF_BAD_INSTPTYPE, "invalid instrument parameter type %d", type); return; } } }
/* This routine checks and sets instrument parameters. npv is number of valid AUpvlist pairs. */ void _af_instparam_set (AFfilehandle file, int instid, AUpvlist pvlist, int npv) { int i, instno, j; if (!_af_filehandle_ok(file)) return; if (!_af_filehandle_can_write(file)) return; if ((instno = _af_handle_instrument_index_from_id(file, instid)) == -1) return; if (AUpvgetmaxitems(pvlist) < npv) npv = AUpvgetmaxitems(pvlist); for (i=0; i < npv; i++) { int param; int type; AUpvgetparam(pvlist, i, ¶m); if ((j = _af_instparam_index_from_id(file->fileFormat, param)) == -1) /* no parameter with that id; ignore */ continue; if (_af_units[file->fileFormat].write.instparamvalid && !_af_units[file->fileFormat].write.instparamvalid(file, pvlist, i)) /* bad parameter value; ignore */ continue; type = _af_units[file->fileFormat].instrumentParameters[j].type; switch (type) { case AU_PVTYPE_LONG: AUpvgetval(pvlist, i, &file->instruments[instno].values[j].l); break; case AU_PVTYPE_DOUBLE: AUpvgetval(pvlist, i, &file->instruments[instno].values[j].d); break; case AU_PVTYPE_PTR: AUpvgetval(pvlist, i, &file->instruments[instno].values[j].v); break; default: return; } } }
/* This routine checks and sets instrument parameters. npv is number of valid AUpvlist pairs. */ void _af_instparam_set (AFfilehandle file, int instid, AUpvlist pvlist, int npv) { if (!_af_filehandle_ok(file)) return; if (!file->checkCanWrite()) return; Instrument *instrument = file->getInstrument(instid); if (!instrument) return; if (AUpvgetmaxitems(pvlist) < npv) npv = AUpvgetmaxitems(pvlist); for (int i=0; i < npv; i++) { int param; AUpvgetparam(pvlist, i, ¶m); int j; if ((j = _af_instparam_index_from_id(file->m_fileFormat, param)) == -1) /* no parameter with that id; ignore */ continue; if (!file->isInstrumentParameterValid(pvlist, i)) /* bad parameter value; ignore */ continue; int type = _af_units[file->m_fileFormat].instrumentParameters[j].type; switch (type) { case AU_PVTYPE_LONG: AUpvgetval(pvlist, i, &instrument->values[j].l); break; case AU_PVTYPE_DOUBLE: AUpvgetval(pvlist, i, &instrument->values[j].d); break; case AU_PVTYPE_PTR: AUpvgetval(pvlist, i, &instrument->values[j].v); break; default: return; } } }
/* ARGSUSED3 */ AUpvlist _afQueryInstrumentParameter (int arg1, int arg2, int arg3, int arg4) { switch (arg1) { /* For the following query types, arg2 is the file format. */ case AF_QUERY_SUPPORTED: if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; return _af_pv_long(_af_units[arg2].instrumentParameterCount != 0); case AF_QUERY_ID_COUNT: if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; return _af_pv_long(_af_units[arg2].instrumentParameterCount); case AF_QUERY_IDS: { int count; int *buffer; if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; count = _af_units[arg2].instrumentParameterCount; if (count == 0) return AU_NULL_PVLIST; buffer = (int *) _af_calloc(count, sizeof (int)); if (buffer == NULL) return AU_NULL_PVLIST; for (int i=0; i<count; i++) buffer[i] = _af_units[arg2].instrumentParameters[i].id; return _af_pv_pointer(buffer); } /* NOTREACHED */ break; /* For the next few query types, arg2 is the file format and arg3 is the instrument parameter id. */ case AF_QUERY_TYPE: { int idx; if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; idx = _af_instparam_index_from_id(arg2, arg3); if (idx<0) return AU_NULL_PVLIST; return _af_pv_long(_af_units[arg2].instrumentParameters[idx].type); } case AF_QUERY_NAME: { int idx; if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; idx = _af_instparam_index_from_id(arg2, arg3); if (idx < 0) return AU_NULL_PVLIST; return _af_pv_pointer(const_cast<char *>(_af_units[arg2].instrumentParameters[idx].name)); } case AF_QUERY_DEFAULT: { int idx; if (arg2 < 0 || arg2 >= _AF_NUM_UNITS) return AU_NULL_PVLIST; idx = _af_instparam_index_from_id(arg2, arg3); if (idx >= 0) { AUpvlist ret = AUpvnew(1); AUpvsetparam(ret, 0, _af_units[arg2].instrumentParameters[idx].id); AUpvsetvaltype(ret, 0, _af_units[arg2].instrumentParameters[idx].type); AUpvsetval(ret, 0, const_cast<AFPVu *>(&_af_units[arg2].instrumentParameters[idx].defaultValue)); return ret; } return AU_NULL_PVLIST; } } _af_error(AF_BAD_QUERY, "bad query selector"); return AU_NULL_PVLIST; }