void run(gce::actor<gce::stackful>& self, gce::aid_t base_id) { try { /// wait 1 second for server setup gce::wait(self, gce::seconds_t(1)); /// make a tcp socket to connnect to server gce::yield_t yield = self.get_yield(); gce::io_service_t& ios = ctx_.get_io_service(); boost::asio::ip::tcp::resolver reso(ios); boost::asio::ip::tcp::resolver::query query(host_, port_); boost::asio::ip::tcp::resolver::iterator itr = reso.async_resolve(query, yield); boost::asio::ip::tcp::socket sock(ios); boost::asio::async_connect(sock, itr, yield); char data[32]; for (std::size_t i=0; i<echo_num_; ++i) { boost::asio::async_write(sock, boost::asio::buffer(data, 32), yield); boost::asio::async_read(sock, boost::asio::buffer(data, 32), yield); /// per second a echo gce::wait(self, gce::seconds_t(1)); } } catch (std::exception& ex) { std::cerr << ex.what() << std::endl; } gce::send(self, base_id, gce::atom("done")); }
void samplv1widget_filt::setReso ( float fReso ) { if (::fabsf(m_fReso - fReso) > 0.001f) { m_fReso = safe_value(fReso); update(); emit resoChanged(reso()); } }
void samplv1widget_filt::wheelEvent ( QWheelEvent *pWheelEvent ) { const int delta = (pWheelEvent->delta() / 60); if (pWheelEvent->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier)) { const int h2 = (height() >> 1); const int y = int(reso() * float(h2)); setReso(float(y + delta) / float(h2)); } else {
// Drag/move curve. void samplv1widget_filt::dragCurve ( const QPoint& pos ) { const int h = height(); const int w = width(); const int dx = (pos.x() - m_posDrag.x()); const int dy = (pos.y() - m_posDrag.y()); if (dx || dy) { const int h2 = (h >> 1); const int x = int(cutoff() * float(w)); const int y = int(reso() * float(h2)); setCutoff(float(x + dx) / float(w)); setReso(float(y - dy) / float(h2)); m_posDrag = pos; } }
void QxtScreenPrivate::init_sys() { #ifdef HAVE_XRANDR Display* display = XOpenDisplay(NULL); Window root = RootWindow(display, screen); XRRScreenConfiguration* config = XRRGetScreenInfo(display, root); // available resolutions & rates if (availResos.isEmpty() || availRates.isEmpty()) { availResos.clear(); availRates.clear(); int sizeCount = 0; XRRScreenSize* sizes = XRRSizes(display, 0, &sizeCount); for (int i = 0; i < sizeCount; ++i) { QSize reso(sizes[i].width, sizes[i].height); if (!availResos.contains(reso)) availResos += reso; int rateCount = 0; short* rates = XRRConfigRates(config, i, &rateCount); for (int j = 0; j < rateCount; ++j) availRates.insertMulti(reso, rates[j]); } } // current resolution & rate if (!currReso.isValid() || currRate < 0) { Rotation rotation; SizeID sizeId = XRRConfigCurrentConfiguration(config, &rotation); currReso = availResos.at(sizeId); currRate = XRRConfigCurrentRate(config); } XRRFreeScreenConfigInfo(config); XCloseDisplay(display); #endif // HAVE_XRANDR }
// Draw curve. void samplv1widget_filt::paintEvent ( QPaintEvent *pPaintEvent ) { QPainter painter(this); const QRect& rect = QWidget::rect(); const int h = rect.height(); const int w = rect.width(); const int h2 = h >> 1; const int h4 = h >> 2; const int w4 = w >> 2; const int w8 = w >> 3; const int iSlope = int(m_fSlope); const int ws = w8 - (iSlope == 1 ? (w8 >> 1) : 0); int x = w8 + int(m_fCutoff * float(w - w4)); int y = h2 - int(m_fReso * float(h + h4)); QPolygon poly(6); QPainterPath path; const int iType = (iSlope == 3 ? 4 : int(m_fType)); // Low, Notch if (iType == 0 || iType == 3) { if (iType == 3) x -= w8; poly.putPoints(0, 6, 0, h2, x - w8, h2, x, h2, x, y, x + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x += w8; } // Band if (iType == 1) { const int y2 = (y + h4) >> 1; poly.putPoints(0, 6, 0, h, x - w8 - ws, h, x - ws, y2, x + ws, y2, x + w8 + ws, h, 0, h); path.moveTo(poly.at(0)); path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); path.lineTo(poly.at(5)); } // High, Notch if (iType == 2 || iType == 3) { if (iType == 3) { x += w8; y = h2; } poly.putPoints(0, 6, x - ws, h, x, y, x, h2, x + w8, h2, w, h2, w, h); path.moveTo(poly.at(0)); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); path.lineTo(poly.at(4)); path.lineTo(poly.at(5)); if (iType == 3) x -= w8; } // Formant if (iType == 4) { const int x2 = (x - w4) >> 2; const int y2 = (y - h4) >> 2; poly.putPoints(0, 6, 0, h2, x2, h2, x - ws, h2, x, y2, x + ws, h, 0, h); path.moveTo(poly.at(0)); #if 0 path.lineTo(poly.at(1)); path.cubicTo(poly.at(2), poly.at(3), poly.at(4)); #else const int n3 = 5; // num.formants const int w3 = (x + ws - x2) / n3 - 1; const int w6 = (w3 >> 1); const int h3 = (h4 >> 1); int x3 = x2; int y3 = y2; for (int i = 0; i < n3; ++i) { poly.putPoints(1, 3, x3, h2, x3 + w6, y3, x3 + w3, y3 + h2); path.cubicTo(poly.at(1), poly.at(2), poly.at(3)); x3 += w3; y3 += h3; } path.lineTo(poly.at(4)); #endif path.lineTo(poly.at(5)); } const QPalette& pal = palette(); const bool bDark = (pal.window().color().value() < 0x7f); const QColor& rgbLite = (isEnabled() ? (bDark ? Qt::darkYellow : Qt::yellow) : pal.mid().color()); const QColor& rgbDark = pal.window().color().darker(180); painter.fillRect(rect, rgbDark); painter.setPen(bDark ? Qt::gray : Qt::darkGray); QLinearGradient grad(0, 0, w << 1, h << 1); grad.setColorAt(0.0f, rgbLite); grad.setColorAt(1.0f, Qt::black); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(grad); painter.drawPath(path); #ifdef CONFIG_DEBUG_0 painter.drawText(QFrame::rect(), Qt::AlignTop|Qt::AlignHCenter, tr("Cutoff(%1) Reso(%2)") .arg(int(100.0f * cutoff())) .arg(int(100.0f * reso()))); #endif painter.setRenderHint(QPainter::Antialiasing, false); painter.end(); QFrame::paintEvent(pPaintEvent); }
bool NucleicAcidTools::symm_match( clipper::MiniMol& molwrk, const clipper::MiniMol& molref ) { clipper::Spacegroup spg1 = clipper::Spacegroup(clipper::Spacegroup::P1); clipper::Spacegroup spgr = molwrk.spacegroup(); clipper::Cell cell = molwrk.cell(); // calculate extent of model clipper::Atom_list atomr = molref.atom_list(); clipper::Range<clipper::ftype> urange, vrange, wrange; clipper::Coord_frac cfr( 0.0, 0.0, 0.0 ); for ( int i = 0; i < atomr.size(); i++ ) { clipper::Coord_frac cf = atomr[i].coord_orth().coord_frac( cell ); cfr += cf; urange.include( cf.u() ); vrange.include( cf.v() ); wrange.include( cf.w() ); } clipper::Coord_frac cf0( urange.min(), vrange.min(), wrange.min() ); clipper::Coord_frac cf1( urange.max(), vrange.max(), wrange.max() ); cfr = (1.0/double(atomr.size())) * cfr; // calculate mask using wrk cell and ref atoms clipper::Resolution reso( 5.0 ); clipper::Grid_sampling grid( spg1, cell, reso ); clipper::Grid_range grng( grid, cf0, cf1 ); grng.add_border(4); clipper::NXmap<float> nxmap( cell, grid, grng ), nxflt( cell, grid, grng ); clipper::EDcalc_mask<float> maskcalc( 2.0 ); nxmap = 0.0; maskcalc( nxmap, atomr ); MapFilterFn_g5 fn; clipper::MapFilter_fft<float> fltr( fn, 1.0, clipper::MapFilter_fft<float>::Relative ); fltr( nxflt, nxmap ); // now score each chain, symmetry and offset in turn for ( int c = 0; c < molwrk.size(); c++ ) { double bestscr = 0.0; int bestsym = 0; clipper::Coord_frac bestoff( 0.0, 0.0, 0.0 ); const clipper::Coord_frac cfh( 0.5, 0.5, 0.5 ); for ( int sym = 0; sym < spgr.num_symops(); sym++ ) { clipper::Atom_list atomw = molwrk[c].atom_list(); clipper::RTop_orth rtop = spgr.symop(sym).rtop_orth( cell ); clipper::Coord_orth cow( 0.0, 0.0, 0.0 ); for ( int a = 0; a < atomw.size(); a++ ) { atomw[a].transform( rtop ); cow += atomw[a].coord_orth(); } if ( atomw.size() > 0 ) cow = (1.0/double(atomw.size())) * cow; clipper::Coord_frac cfw = cow.coord_frac( cell ); clipper::Coord_frac cfwt = cfw.lattice_copy_near( cfr - cfh ); clipper::Coord_frac off0 = cfwt - cfw; // try offsets for ( double du = 0.0; du <= 1.01; du += 1.0 ) for ( double dv = 0.0; dv < 1.01; dv += 1.0 ) for ( double dw = 0.0; dw < 1.01; dw += 1.0 ) { clipper::Coord_frac off( rint( off0.u() ) + du, rint( off0.v() ) + dv, rint( off0.w() ) + dw ); clipper::Coord_orth ofo = off.coord_orth( cell ); double scr = 0.0; for ( int a = 0; a < atomw.size(); a++ ) { clipper::Coord_orth coa = atomw[a].coord_orth() + ofo; clipper::Coord_grid cga = nxflt.coord_map( coa ).coord_grid(); if ( nxflt.in_map( cga ) ) scr += nxflt.get_data( cga ); } if ( scr > bestscr ) { bestscr = scr; bestsym = sym; bestoff = off; } } } // now transform using the best operator clipper::Coord_orth cot = bestoff.coord_orth( cell ); clipper::RTop_orth rtop = spgr.symop(bestsym).rtop_orth( cell ); rtop = clipper::RTop_orth( rtop.rot(), rtop.trn()+cot ); molwrk[c].transform( rtop ); } return true; }