void EnvelopeComponent::setEnv(Env const& env) { clear(); double time = 0.0; const Buffer& levels = env.getLevels(); const Buffer& times = env.getTimes(); const EnvCurveList& curves = env.getCurves(); ugen_assert(levels.size() == (times.size()+1)); EnvelopeHandleComponent* handle = addHandle(time, (double)levels[0], EnvCurve::Linear); quantiseHandle(handle); for(int i = 0; i < times.size(); i++) { time += times[i]; handle = addHandle(time, (double)levels[i+1], curves[i]); quantiseHandle(handle); } releaseNode = env.getReleaseNode(); loopNode = env.getLoopNode(); }
void Table::makeTableEditable() { // Adding handles to make table editable... handles.clear(); double angle, prevAngle; prevAngle = atan2(envPath.getPointAlongPath(2).getY() - envPath.getPointAlongPath(1).getY(), envPath.getPointAlongPath(2).getX() - envPath.getPointAlongPath(1).getX()) * 180 / 3.14; //add first handle addHandle (envPath.getPointAlongPath(1).getX(), envPath.getPointAlongPath(1).getY()); for(int i=2; i<envPath.getLength(); i++){ angle = atan2(envPath.getPointAlongPath(i).getY() - envPath.getPointAlongPath(i-1).getY(), envPath.getPointAlongPath(i).getX() - envPath.getPointAlongPath(i-1).getX()) * 180 / 3.14; //String msg; //msg << "i:" << i << " Path(" << envPath.getPointAlongPath(i).getX() << ", " << envPath.getPointAlongPath(i).getY() << ")" //<< " Direction:" << angle; //Logger::writeToLog(msg); //make sure it's not a NaN if(CabbageUtils::isNumber(angle)) //this is not right yet as it adds too many handles.... //check that the angle has changed by at least 30 degrees, again, needs work if(((int)prevAngle!=(int)angle)&& abs(prevAngle-angle)>30) addHandle (envPath.getPointAlongPath(i).getX(), envPath.getPointAlongPath(i).getY()); prevAngle = angle; } addHandle (envPath.getPointAlongPath(envPath.getLength()).getX(), envPath.getPointAlongPath(envPath.getLength()).getY()); }
///////////////////////////////////////////////////////// // // pix_video // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// pix_video :: pix_video(int argc, t_atom*argv) : m_videoHandle(NULL), m_driver(-1), m_running(UNKNOWN), m_infoOut(NULL) { gem::PluginFactory<gem::plugins::video>::loadPlugins("video"); std::vector<std::string>ids=gem::PluginFactory<gem::plugins::video>::getIDs(); addHandle(ids, "v4l2"); addHandle(ids, "v4l"); addHandle(ids, "dv4l"); addHandle(ids); m_infoOut = outlet_new(this->x_obj, 0); /* * calling driverMess() would immediately startTransfer(); * we probably don't want this in initialization phase */ if(m_videoHandles.size()>0) { m_driver=-1; } else { error("no video backends found!"); } std::string dev=gem::RTE::Symbol(argc, argv); if(!dev.empty()) deviceMess(dev); }
///////////////////////////////////////////////////////// // // pix_record // ///////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////// pix_record :: pix_record(int argc, t_atom *argv): m_banged(false), m_automatic(true), m_outNumFrames(NULL), m_outInfo(NULL), m_currentFrame(-1), m_maxFrames(0), m_recording(false), m_handle(NULL), m_pimpl(new PIMPL()) { if (argc != 0){ error("ignoring arugments"); } m_outNumFrames = outlet_new(this->x_obj, 0); m_outInfo = outlet_new(this->x_obj, 0); gem::PluginFactory<gem::plugins::record>::loadPlugins("record"); std::vector<std::string>ids=gem::PluginFactory<gem::plugins::record>::getIDs(); addHandle(ids, "QT"); addHandle(ids, "QT4L"); addHandle(ids); if(m_allhandles.size()>0) { } else { error("no video backends found!"); } m_handles=m_allhandles; getCodecList(); }
//==================================================== void Table::createHandlesFromTable(int points) { handles.clear(); Colour col; editMode=true; int x; float end = getWidth(); float scaleX = .99; if(points>tableSize) { points=tableSize; fixedEnvelope = true; } float segmentIncr = (float)tableSize/(float)points; if(fixedEnvelope && drawHorizontalSegments) { handleWidth = getWidth()/tableSize; col = activeColour; scaleX = 1; } else col = activeColour.contrasting(.5); addHandle(0, convertAmpToPixel(tableData.amps[0]), true, handleWidth-2, col); for(int i=segmentIncr; i<tableSize; i+=segmentIncr) { int x = int((float(i)/(float)tableSize)*getWidth()*scaleX); addHandle(x, convertAmpToPixel(tableData.amps[i]), (i==0 || i==tableSize, fixedEnvelope), handleWidth, col); } addHandle(end, convertAmpToPixel(tableData.amps[0]), true, handleWidth, col); }
void EnvelopeComponent::setMinMaxNumHandles(int min, int max) { if(min <= max) { minNumHandles = min; maxNumHandles = max; } else { minNumHandles = max; maxNumHandles = min; } Random rand(Time::currentTimeMillis()); if(handles.size() < minNumHandles) { int num = minNumHandles-handles.size(); for(int i = 0; i < num; i++) { double randX = rand.nextDouble() * (domainMax-domainMin) + domainMin; double randY = rand.nextDouble() * (valueMax-valueMin) + valueMin; addHandle(randX, randY, EnvCurve::Linear); } } else if(handles.size() > maxNumHandles) { int num = handles.size()-maxNumHandles; for(int i = 0; i < num; i++) { removeHandle(handles.getLast()); } } }
EnvelopeHandleComponent* EnvelopeComponent::addHandle(int newX, int newY, EnvCurve curve) { #ifdef MYDEBUG printf("MyEnvelopeComponent::addHandle(%d, %d)\n", newX, newY); #endif return addHandle(convertPixelsToDomain(newX), convertPixelsToValue(newY), curve); }
//==================================================== void Table::mouseDown (const MouseEvent& e) { if(editMode==true) if(fixedEnvelope==false) if(e.mods.isShiftDown() == true) draggingHandle = addHandle (e.x, e.y, false, handleWidth, activeColour.contrasting(.5)); }
void EnvelopeComponent::mouseDown(const MouseEvent& e) { #ifdef MYDEBUG printf("MyEnvelopeComponent::mouseDown(%d, %d)\n", e.x, e.y); #endif if(e.mods.isShiftDown()) { // not needed ? } else if(e.mods.isCtrlDown()) { if(getAllowCurveEditing()) { float timeAtClick = convertPixelsToDomain(e.x); int i; EnvelopeHandleComponent* handle = 0; for(i = 0; i < handles.size(); i++) { handle = handles.getUnchecked(i); if(handle->getTime() > timeAtClick) break; } if(PopupComponent::getActivePopups() < 1) { EnvelopeHandleComponent* prev = handle->getPreviousHandle(); if(!prev) { EnvelopeCurvePopup::create(handle, getScreenX()+e.x, getScreenY()+e.y); } else { EnvelopeCurvePopup::create(handle, (handle->getScreenX() + prev->getScreenX())/2, jmax(handle->getScreenY(), prev->getScreenY())+10); } } } } else { draggingHandle = addHandle(e.x,e.y, EnvCurve::Linear); if(draggingHandle != 0) { setMouseCursor(MouseCursor::NoCursor); draggingHandle->mouseDown(e.getEventRelativeTo(draggingHandle)); draggingHandle->updateLegend(); } } }
/* hid_t H5Freopen(hid_t file_id ) */ SEXP _H5Freopen( SEXP _file_id ) { hid_t file_id = INTEGER(_file_id)[0]; hid_t hid = H5Freopen( file_id ); addHandle(file_id); SEXP Rval; PROTECT(Rval = allocVector(INTSXP, 1)); INTEGER(Rval)[0] = hid; UNPROTECT(1); return Rval; }
/* TODO more parameters: hid_t fcpl_id, hid_t fapl_id */ SEXP _H5Fcreate( SEXP _name, SEXP _flags ) { const char *name = CHAR(STRING_ELT(_name, 0)); unsigned flags = INTEGER(_flags)[0]; hid_t hid = H5Fcreate( name, flags, H5P_DEFAULT, H5P_DEFAULT ); addHandle(hid); SEXP Rval; PROTECT(Rval = allocVector(INTSXP, 1)); INTEGER(Rval)[0] = hid; UNPROTECT(1); return Rval; }
void UBEditableGraphicsPolygonItem::addPoint(const QPointF & point) { QPainterPath painterPath = path(); if (painterPath.elementCount() == 0) { painterPath.moveTo(point); // For the first point added, we must use moveTo(). setPath(painterPath); mStartEndPoint[0] = point; } else { // If clic on first point, close the polygon // TODO à terme : utiliser la surface de la première poignée. QPointF pointDepart(painterPath.elementAt(0).x, painterPath.elementAt(0).y); QPointF pointFin(painterPath.elementAt(painterPath.elementCount()-1).x, painterPath.elementAt(painterPath.elementCount()-1).y); QGraphicsEllipseItem poigneeDepart(pointDepart.x()-10, pointDepart.y()-10, 20, 20); QGraphicsEllipseItem poigneeFin(pointFin.x()-10, pointFin.y()-10, 20, 20); if (poigneeDepart.contains(point)) { setClosed(true); } else { if(poigneeFin.contains(point)){ mIsInCreationMode = false; mOpened = true; }else{ painterPath.lineTo(point); setPath(painterPath); } } mStartEndPoint[1] = point; } if(!mClosed && !mOpened){ UBFreeHandle *handle = new UBFreeHandle(); addHandle(handle); handle->setParentItem(this); handle->setEditableObject(this); handle->setPos(point); handle->setId(path().elementCount()-1); handle->hide(); } }
RectTool::RectTool(AddingType type, Canvas *canvas) : Tool(canvas), d(new Data) { d->layerController = canvas->findChild<LayerUIController *>(); d->updateManager = new CanvasUpdateManager(this); connect(d->updateManager, SIGNAL(updateTilesRequested(QPointSet)), this, SIGNAL(requestUpdate(QPointSet))); // set modes d->addingType = type; if (d->addingType == NoAdding) d->selectingMode = SelectImmediately; else d->selectingMode = SelectLater; // create graphics items { auto group = new QGraphicsItemGroup(); group->setHandlesChildEvents(false); setGraphicsItem(group); { auto frame = new FrameGraphicsItem(group); d->frameItem = frame; } } addHandle(Top | Left, 1); addHandle(Top | Right, 1); addHandle(Bottom | Left, 1); addHandle(Bottom | Right, 1); addHandle(Top, 0); addHandle(Bottom, 0); addHandle(Left, 0); addHandle(Right, 0); connect(layerScene(), SIGNAL(selectionChanged(QList<LayerConstRef>,QList<LayerConstRef>)), this, SLOT(updateSelected())); connect(layerScene(), SIGNAL(layerChanged(LayerConstRef)), this, SLOT(updateLayer(LayerConstRef))); connect(canvas, SIGNAL(transformsChanged(SP<const CanvasTransforms>)), this, SLOT(updateGraphicsItems())); updateSelected(); }
// Check for file descriptors >= FD_SETSIZE // which can't be returned in an fdset // This is a little hacky, but necessary given cURL's APIs int CurlMultiAwait::addHighHandles(req::ptr<CurlMultiResource> multi) { int count = 0; auto easy_handles = multi->getEasyHandles(); for (ArrayIter iter(easy_handles); iter; ++iter) { Variant easy_handle = iter.second(); auto easy = dyn_cast_or_null<CurlResource>(easy_handle); if (!easy) continue; long sock; if ((curl_easy_getinfo(easy->get(), CURLINFO_LASTSOCKET, &sock) != CURLE_OK) || (sock < FD_SETSIZE)) { continue; } // No idea which type of event it needs, ask for everything addHandle(sock, AsioEventHandler::READ_WRITE); ++count; } return count; }
// Ask curl_multi for its handles directly // This is preferable as we get to know which // are blocking on reads, and which on writes. int CurlMultiAwait::addLowHandles(req::ptr<CurlMultiResource> multi) { fd_set read_fds, write_fds; int max_fd = -1, count = 0; FD_ZERO(&read_fds); FD_ZERO(&write_fds); if ((CURLM_OK != curl_multi_fdset(multi->get(), &read_fds, &write_fds, nullptr, &max_fd)) || (max_fd < 0)) { return count; } for (int i = 0 ; i <= max_fd; ++i) { int events = 0; if (FD_ISSET(i, &read_fds)) events |= AsioEventHandler::READ; if (FD_ISSET(i, &write_fds)) events |= AsioEventHandler::WRITE; if (events) { addHandle(i, events); ++count; } } return count; }
void CADLayer::addHandle( long handle, CADObject::ObjectType type, long cadinserthandle ) { #ifdef _DEBUG cout << "addHandle: " << handle << " type: " << type << endl; #endif //_DEBUG if( type == CADObject::ATTRIB || type == CADObject::ATTDEF ) { unique_ptr<CADAttdef> attdef( static_cast< CADAttdef *>( pCADFile->GetGeometry( this->getId() - 1, handle ) ) ); attributesNames.insert( attdef->getTag() ); } if( type == CADObject::INSERT ) { // TODO: transform insert to block of objects (do we need to transform // coordinates according to insert point)? unique_ptr<CADObject> insert( pCADFile->GetObject( handle, false ) ); CADInsertObject * pInsert = static_cast<CADInsertObject *>(insert.get()); if( nullptr != pInsert ) { unique_ptr<CADObject> blockHeader( pCADFile->GetObject( pInsert->hBlockHeader.getAsLong(), false ) ); CADBlockHeaderObject * pBlockHeader = static_cast<CADBlockHeaderObject *>(blockHeader.get()); if( nullptr != pBlockHeader ) { #ifdef _DEBUG if( pBlockHeader->bBlkisXRef ) { assert( 0 ); } #endif //_DEBUG auto dCurrentEntHandle = pBlockHeader->hEntities[0].getAsLong(); auto dLastEntHandle = pBlockHeader->hEntities[pBlockHeader->hEntities.size() - 1].getAsLong(); // FIXME: in 2000+ entities probably has no links to each other. if( dCurrentEntHandle == dLastEntHandle ) // Blocks can be empty (contain no objects) return; while( true ) { unique_ptr<CADEntityObject> entity( static_cast< CADEntityObject * >( pCADFile->GetObject( dCurrentEntHandle, true ) ) ); if( dCurrentEntHandle == dLastEntHandle ) { if( entity != nullptr ) { addHandle( dCurrentEntHandle, entity->getType(), handle ); Matrix mat; mat.translate( pInsert->vertInsertionPoint ); mat.scale( pInsert->vertScales ); mat.rotate( pInsert->dfRotation ); transformations[dCurrentEntHandle] = mat; break; } else { assert( 0 ); } } if( entity != nullptr ) { addHandle( dCurrentEntHandle, entity->getType(), handle ); Matrix mat; mat.translate( pInsert->vertInsertionPoint ); mat.scale( pInsert->vertScales ); mat.rotate( pInsert->dfRotation ); transformations[dCurrentEntHandle] = mat; if( entity->stCed.bNoLinks ) ++dCurrentEntHandle; else dCurrentEntHandle = entity->stChed.hNextEntity.getAsLong( entity->stCed.hObjectHandle ); } else { assert ( 0 ); } } } } return; } if( isCommonEntityType( type ) ) { if( type == CADObject::IMAGE ) imageHandles.push_back( handle ); else { if( pCADFile->isReadingUnsupportedGeometries() == false ) { if( isSupportedGeometryType( type ) ) { if( geometryTypes.size() == 0 ) geometryTypes.push_back( type ); if( find( geometryTypes.begin(), geometryTypes.end(), type ) == geometryTypes.end() ) { geometryTypes.push_back( type ); } geometryHandles.push_back( make_pair( handle, cadinserthandle ) ); } } else { if( geometryTypes.size() == 0 ) geometryTypes.push_back( type ); if( find( geometryTypes.begin(), geometryTypes.end(), type ) == geometryTypes.end() ) { geometryTypes.push_back( type ); } geometryHandles.push_back( make_pair( handle, cadinserthandle ) ); } } } }