void mythread::run()
{
    //ovde thread krece sa izvrsavanjem

	threadFrame myFrame;
	QTimer *timer = new QTimer(0);
	
	
	timer->start(10); 
	qDebug() << socketDescriptor << "Starting thread";
	socket = new QTcpSocket();
	if (!socket->setSocketDescriptor(this->socketDescriptor))
	{
		emit error(socket->error());
		return;
	}
	myFrame.frame = *sysFrame;
	myFrame.socketDescriptor=this->socketDescriptor;
	sysFrameList->append(myFrame);
	connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()),Qt::DirectConnection);
	connect(socket,SIGNAL(disconnected()),this,SLOT(disconnected()),Qt::DirectConnection);
	connect(timer,SIGNAL(timeout()),this,SLOT(timeUp()),Qt::DirectConnection); //still need this.
	connect(this,SIGNAL(timeSig()),this,SLOT(readyWrite()),Qt::DirectConnection);

	qDebug() << socketDescriptor << "Client connected.";
	QMutex lock;



	exec(); //thread will stay alive until we tell it to close
}
示例#2
0
void ExportMidi::PauseMap::calculate(const Score* s)
      {
      Q_ASSERT(s);
      TimeSigMap* sigmap = s->sigmap();
      TempoMap* tempomap = s->tempomap();

      this->insert(std::pair<const int, int> (0, 0)); // can't start with a pause

      tempomapWithPauses = new TempoMap();
      tempomapWithPauses->setRelTempo(tempomap->relTempo());

      foreach(const RepeatSegment* rs, *s->repeatList()) {
            int startTick  = rs->tick;
            int endTick    = startTick + rs->len();
            int tickOffset = rs->utick - rs->tick;

            auto se = tempomap->lower_bound(startTick);
            auto ee = tempomap->lower_bound(endTick+1); // +1 to include first tick of next RepeatSegment

            for (auto it = se; it != ee; ++it) {
                  int tick = it->first;
                  int utick = tick + tickOffset;

                  if (it->second.pause == 0.0) {
                        // We have a regular tempo change. Don't include tempo change from first tick of next RepeatSegment (it will be included later).
                        if (tick != endTick)
                              tempomapWithPauses->insert(std::pair<const int, TEvent> (this->addPauseTicks(utick), it->second));
                        }
                  else {
                        // We have a pause event. Don't include pauses from first tick of current RepeatSegment (it was included in the previous one).
                        if (tick != startTick) {
                              Fraction timeSig(sigmap->timesig(tick).timesig());
                              qreal quarterNotesPerMeasure = (4.0 * timeSig.numerator()) / timeSig.denominator();
                              int ticksPerMeasure =  quarterNotesPerMeasure * MScore::division; // store a full measure of ticks to keep barlines in same places
                              tempomapWithPauses->setTempo(this->addPauseTicks(utick), quarterNotesPerMeasure / it->second.pause); // new tempo for pause
                              this->insert(std::pair<const int, int> (utick, ticksPerMeasure + this->offsetAtUTick(utick))); // store running total of extra ticks
                              tempomapWithPauses->setTempo(this->addPauseTicks(utick), it->second.tempo); // restore previous tempo
                              }
                        }
                  }
            }
      }
void newConnThread::run()
{
    //this is where the thread actually starts.
    socket = new QTcpSocket;
    if(!socket->setSocketDescriptor(this->socketDescriptor))
    {
        exit(1);
    }
    //cool. we've got a connection.
    //setup timer
    timer = new QTimer;
    timer->start(500);

    //time to connect some signals and slots.
    connect(socket,SIGNAL(readyRead()),this,SLOT(handleReadyRead()));
    connect(socket,SIGNAL(disconnected()),this,SLOT(handleDisconnected()));
    connect(timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
    connect(this,SIGNAL(timeSig()),this,SLOT(handleWrite()));
    //make the thread run even when this run function goes out of scope.
    exec();
}
void newConnThread::handleTimeout()
{
    //this handles changing the permissions of the socket so that
    //the timer can control the writing indirectly.
    emit timeSig();
}
void mythread::timeUp() //probably does not need to be remade.
{
	emit timeSig();
}