Esempio n. 1
0
 void beginDrawing()
 {
     // Retrieve user-profile directory from envirnment variable
     char * user_dir = getenv("USERPROFILE"); // Windows
     if (!user_dir)
         user_dir = getenv("HOME"); // POSIX
     if (user_dir)
     { // Environment variable found, connect to a file in user's profile directory
         std::string file_name(user_dir);
         file_name.append("/.vibes.json");
         beginDrawing(file_name);
     }
     else
     { // Connect to a file in working directory
         beginDrawing("vibes.json");
     }
 }
Esempio n. 2
0
void drawGame(Game *game)
{
	beginDrawing(game->renderer);
	
	drawMap(game->map, game->renderer);
	drawPerso(game->renderer);
	
	endDrawing(game->renderer);
}
Esempio n. 3
0
void SummaryDrawWidget::paintEvent( QPaintEvent * )
{
  Channel *ch;

  //if((right - left) <= 0) return;
  View *view = gdata->view;
/*  if (view->totalTime() == 0) {
    buffer = new QPixmap(size());
    buffer->fill(myBackgroundColor);
    bitBlt(this, 0, 0, buffer); */
  if(gdata->totalTime() < 0) return;

  double timeRatio = double(width()) / gdata->totalTime();
  double pitchRatio = double(height()) / (gdata->topPitch() / scaler);

  beginDrawing();

  //draw all the channels
  for(int j = 0; j < (int)gdata->channels.size(); j++) {
    ch = gdata->channels.at(j);
    if(!ch->isVisible()) continue;

    //drawChannel(ch, p, view->leftTime(), (view->totalTime() / (double) width()), 0.0f, (double) view->topNote() / (double) height(), DRAW_VIEW_SUMMARY);
    drawChannel(*this, ch, p, gdata->leftTime(), view->currentTime(), (gdata->totalTime() / (double) width()), 0.0f, (double) gdata->topPitch() / (double) height(), DRAW_VIEW_SUMMARY);
  }

  //draw the view rectangle 
  p.setPen(QPen(colorGroup().highlight(), 1));
  p.drawRect(int((gdata->leftTime()+view->viewLeft())*timeRatio), height()-1-int((view->viewTop())*pitchRatio),
             int(view->viewWidth()*timeRatio), int(view->viewHeight()*pitchRatio));

  //draw the current time line
  p.setPen(QPen(colorGroup().foreground(), 1));
  //p.moveTo(int((gdata->leftTime()+view->currentTime())*timeRatio), 0);
  //p.lineTo(int((gdata->leftTime()+view->currentTime())*timeRatio), height()-1);
  p.drawLine(int((gdata->leftTime()+view->currentTime())*timeRatio), 0, 
             int((gdata->leftTime()+view->currentTime())*timeRatio), height()-1);

  endDrawing();
}
Esempio n. 4
0
void VolumeMeterWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();
  //if(!active) { return; printf("failed active\n"); }
  //AnalysisData *analysisData = active->currentLookup();
  //if(!analysisData) { return; printf("failed currentLookup\n"); }

  beginDrawing(false);
  fillBackground(colorGroup().background());
  p.setFont(_font);
  
  // Work out how many labels we can draw
  QFontMetrics fm = p.fontMetrics();
  int labelWidth = fm.width("-60"); // Since we'll have two characters normally
  int halfLabelWidth = labelWidth / 2;
  int stopWidth = fm.width("0dB") / 2;
  int realWidth = width() - stopWidth - halfLabelWidth; // The actual width of the data
  int places = labelNumbers[MIN(realWidth / 20, 6) - 1]; // How many labels we should have
  int pixelStep = toInt(double(realWidth) / double(places)); // How many pixels to jump between labels/markers
  //int stopPixel = halfLabelWidth + places * pixelStep; // The actual pixel to stop drawing on
  //int fontSize = 9;
  //int lineY = height() - fontSize - 8;
  int lineY = height() - _fontSize - 2;

  int labelStep = 10;

  // Determine how many dB we should jump by each time
  switch (places) {
    case 1:
    labelStep = 60;
    break;
    case 2:
    labelStep = 30;
    break;
    case 3:
    labelStep = 20;
    break;
    case 6:
    labelStep = 10;
    break;
    default:
    myassert(false); // This should never happen!
    break;
  }


  // Draw horizontal line
  //p.setPen(colorGroup().foreground());
  p.setPen(Qt::black);
  //p.drawLine(halfLabelWidth, lineY, stopPixel, lineY);
  //p.setFont(QFont("AnyStyle", fontSize));

  int y = height() - (lineY/2)- 1;

  for (int i=0; i < places; i++) {
    int x = i * pixelStep;
    p.drawText(x, y, QString::number(-60 + (i * labelStep)));
  }
  p.drawText(places * pixelStep - 2, y, "0dB");

/*
  // Draw the number markers
  int secondaryMarker = pixelStep / 2;
  for (int j=0; j <= places; j++) {
    int major = j * pixelStep + halfLabelWidth;
    int minor = major + secondaryMarker;
    p.drawLine(major, lineY, major, lineY + 5);
    p.drawLine(minor, lineY, minor, lineY + 3);
  }
*/
  
  QColor colour;
  //if (active != NULL && active->hasAnalysisData()) {
  //printf("%d, %d\n", active->chunkAtCurrentTime(), active->totalChunks());
  //int chunk = active->chunkAtCurrentTime() - 1;
  //printf("%d, %d\n", active->chunkNum(), active->totalChunks());
  float theVal[2];
  if (active != NULL && active->isValidChunk(active->currentChunk())) {
    int chunk = active->currentChunk();
    if(active->getParent()->numChannels() > 1) {
      theVal[0] = active->getParent()->channels(0)->dataAtChunk(chunk)->getMaxIntensityDB();
      theVal[1] = active->getParent()->channels(1)->dataAtChunk(chunk)->getMaxIntensityDB();
    } else {
      theVal[0] = theVal[1] = active->dataAtChunk(chunk)->getMaxIntensityDB();
    }
  } else {
    theVal[0] = theVal[1] = 0.0;
  }
  
  //AnalysisData &analysisData = active->dataAtCurrentTime();
  //int val = toInt(analysisData->maxIntensity * double(width()));
  //double decibels = 20.0 * log10(analysisData.maxIntensity);
  for(int chnl=0; chnl<2; chnl++) {
    //double decibels = 20.0 * log10(theVal[chnl]);
    double decibels = theVal[chnl];
    // We'll show 60 dB
    //int val = toInt(((double(width() - halfLabelWidth) / 60.0) * decibels) + width() - halfLabelWidth);
    int val = toInt((double(realWidth / 60.0) * decibels) + realWidth);

    //**************************************************************
    //int barWidth = 12; // Not right - needs to be based on realWidth
    //int barWidth = 5; // Not right - needs to be based on realWidth
    int barWidth = 5; // Not right - needs to be based on realWidth
    //**************************************************************
    // double step = realWidth / floor(realWidth / 12)



    //for(int j=halfLabelWidth; j<=val; j+=10) {
    for(int j=halfLabelWidth; j<=realWidth; j+=10) {
      if(j < val) {
        //int col = MIN(MAX(j*255/width(), 0), 255);
        //p.fillRect(j-3, 0, 3, height()-1, QColor(col, 255 - col, 0));
        if ( j < (width() * 0.5)) colour = Qt::blue;
        else if ( j < (width() * 0.85)) colour = QColor(255, 120, 60);
        else colour = Qt::red;
      } else {
        colour = QColor(198, 198, 198);
      }
      
      if(chnl == 0)
        p.fillRect(j, 2, barWidth, lineY/2 -3, colour);
      else
        p.fillRect(j, height() - (lineY/2) + 1, barWidth, lineY/2 -3, colour);
      //p.setPen(Qt::black);
      //p.drawRect(j, 0, barWidth, height()-20+1);
    }
    //p.fillRect(0, height()-1-val, width()-1, height()-1, QColor(Qt::red));
  }

  endDrawing();  
/*
    float pos;
    float *data;
    float step = float(width()) / float(buffer->length());
    // int h2 = height() / 2;
    float hf = float(height());
    unsigned int j;
    int cur=0, prev=0;

    int c;
    //float *temp[gdata->process_channels];
    float *temp[2];

    for(c = 0; c < gdata->process_channels; c++)
        temp[c] = (float *)malloc(buffer->length() * sizeof(float));
    buffer->lock();
    for(c = 0; c < gdata->process_channels; c++)
        memcpy(temp[c], buffer->begin(c), buffer->length() * sizeof(float));
    buffer->unlock();


    QPainter p;
    p.begin(this);

    for(c=0; c < gdata->process_channels; c++) {
	data = temp[c]; //buffer->data[c];
	pos = 0.0;
	if(c == 0) p.setPen(QPen(red, 4));
	else p.setPen(QPen(blue, 4));
	prev = height()-1-int(data[0]*hf);
	//p.moveTo(0, height()-1-int(data[0]*hf));
	for(j=0; j<buffer->length(); j++, pos+=step) {
	    //p.lineTo(j, h2-int(interpolate_linear(buffer->length(), data, pos)*h2f));
	    cur = height()-1-int(data[j]*hf);
	    //p.lineTo(j, cur);
	    p.drawLine(int(pos-step), prev, int(pos), cur);
	    prev = cur;
	}
    }
    p.end();
*/
}
Esempio n. 5
0
void TimeAxis::paintEvent(QPaintEvent *)
{
  int frameWidth = 2;
  const int	h = height(), w = width() - 2*frameWidth;
  int fontSpace = _fontSize+2;
  
  beginDrawing(false);
  fillBackground(colorGroup().background());

  double timeStep = timeWidth() / double(w) * 150.0; //time per 150 pixels
  double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10

  //choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
  int largeFreq;
  if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
  else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
  else { largeFreq = 2; timeScaleBase /= 2; }
    
  // Draw Ruler Numbers
  p.setBrush(Qt::black);
  //p.setFont(QFont("AnyStyle", h / 2 - 7));
  p.setFont(_font);
  double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
  int x, largeCounter=-1;
  
  //precalculate line sizes (for efficiency)
  int smallLineTop = 0;
  int smallLineBottom = 0;
  if(_numbersOnTop) {
    smallLineTop = h - 1 - (h - 1 - fontSpace)/2;
    smallLineBottom = h - 1;
  } else {
    smallLineTop = 0;
    smallLineBottom = (h - 1 - fontSpace) / 2;
  }
  int bigLineTop = 0;
  int bigLineBottom = 0;
  if(_numbersOnTop) {
    bigLineTop = fontSpace;
    bigLineBottom = h - 1;
  } else {
    bigLineTop = 0;
    bigLineBottom = h - 1 - fontSpace;
  }
  int textBottom = 0;
  if(_numbersOnTop) textBottom = _fontSize;
  else textBottom = h - 1;
    
  for(; timePos <= rightTime(); timePos += timeScaleBase) {
    if(++largeCounter == largeFreq) {
      largeCounter = 0;
      //draw the bigger lines and the numbers
      //QString numString = QString::number(timePos);

      double newTime = myround(timePos / timeScaleBase) * timeScaleBase;
      QString mins;
      double secs = fmod(newTime, 60.0);

      if (timePos < 0) {
        mins = "-" + QString::number(int(ceil(newTime / 60)));
        secs *= -1;
      } else {
        mins = QString::number(int(floor(newTime / 60)));
      }

      QString seconds = QString::number(secs);
      if (secs < 10 && secs > -10) {
        seconds = "0" + seconds;
      }
      
      QString numString = mins + ":" + seconds;
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawText(x - (p.fontMetrics().width(numString) / 2), textBottom, numString);
      p.drawLine(x, bigLineTop, x, bigLineBottom);
    } else {
      //draw the smaller lines
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawLine(x, smallLineTop, x, smallLineBottom);
    }
  }
  //draw the horizontal line
  if(_numbersOnTop) {
    p.drawLine(0, h-1, width(), h-1);
  } else {
    p.drawLine(0, 0, width(), 0);
  }
  endDrawing();
}
Esempio n. 6
0
void CorrelationWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();

  AnalysisData *data = NULL;
  int chunk=0;
  double dh2 = double(height()-1) / 2.0;
  int j, x, y;
    
  beginDrawing(false);
    
  if(active) {
    
    active->lock();
    chunk = active->currentChunk();
    data = active->dataAtChunk(chunk);

    //int centerX = width() / 2;
    if(data) {
      double freq = data->getFundamentalFreq();
      double period = double(active->rate()) / freq;
      //double numPeriods = double(active->size()) / period;
      double scaleX = period * double(width()) / double(active->nsdfData.size()); //pixels per period
      
      //draw alternating background color indicating period
      if(gdata->view->backgroundShading() && period > 4.0 && period < double(active->nsdfData.size())) {
        int n = int(ceil(double(width()) / scaleX)); //number of colored patches
        p.setPen(Qt::NoPen);
        QColor color1 = colorBetween(gdata->backgroundColor(), gdata->shading1Color(), data->getCorrelation());
        QColor color2 = colorBetween(gdata->backgroundColor(), gdata->shading2Color(), data->getCorrelation());
        for(j = 0; j<n; j++) {
          x = toInt(scaleX*double(j));
          p.setBrush((j%2) ? color1 : color2);
          p.drawRect(x, 0, toInt(scaleX*double(j+1)) - toInt(scaleX*double(j)), height());
        }
        p.setPen(colorBetween(gdata->backgroundColor(), Qt::black, 0.3 * data->getCorrelation()));
        for(j = 0; j<n; j++) {
          x = toInt(scaleX*double(j));
          p.drawLine(x, 0, x, height());
        }
      } else {
        clearBackground();
      }
      QString numPeriodsText;
      numPeriodsText.sprintf("Period = %lf", period);
      p.setPen(Qt::black);
      p.drawText(5, height() - 8, numPeriodsText);
    } else {
      clearBackground();
    }
  } else {
    clearBackground();
  }

  //draw the horizontal center line
  p.setPen(QPen(colorBetween(colorGroup().background(), Qt::black, 0.3), 0));
  p.drawLine(0, toInt(dh2), width(), toInt(dh2));

  if(active) { 
    if(gdata->doingFreqAnalysis()) {
      int w = width() / 2; //only do every second pixel (for speed)
      //draw the waveform
      if(int(pointArray.size()) != w) pointArray.resize(w);
      if(lookup.size() != w) lookup.resize(w);

      NoteData *currentNote = active->getCurrentNote();
      Array1d<float> *input = &(active->nsdfData);
      if(currentNote) {
        if(aggregateMode == 1) input = &currentNote->nsdfAggregateData;
        else if(aggregateMode == 2) input = &currentNote->nsdfAggregateDataScaled;
      }
      //bresenham1d(*input, lookup);
      maxAbsDecimate1d(*input, lookup);
      for(int j=0; j<w; j++) {
        pointArray.setPoint(j, j*2, toInt(dh2 - lookup[j]*dh2));
      }

      p.setPen(QPen(active->color, 0));
      p.drawPolyline(pointArray);
    }
    if(data && (aggregateMode == 0)) {
      double ratio = double(width()) / double(active->nsdfData.size()); //pixels per index
      //float highest = active->nsdfData.at(data->highestCorrelationIndex);
      //float chosen = active->nsdfData.at(data->chosenCorrelationIndex);
      
      //draw a dot at all the period estimates
      p.setPen(Qt::blue);
      p.setBrush(Qt::blue);
      for(j=0; j<int(data->getPeriodEstimatesSize()); j++) {
        x = toInt(double(data->getPeriodEstimatesAt(j)) * ratio);
        y = toInt(dh2 - data->getPeriodEstimatesAmpAt(j) * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }
      
      if(data->getHighestCorrelationIndex() >= 0) {
        float highest = data->getPeriodEstimatesAmpAt(data->getHighestCorrelationIndex());
        //draw threshold line
        p.setPen(QPen(colorBetween(colorGroup().background(), Qt::black, 0.3), 0));
        y = toInt(dh2 - (highest * active->threshold()) * dh2);
        p.drawLine(0, y, width(), y);
      
        //draw a dot at the highest correlation period
        p.setPen(Qt::black);
        p.setBrush(Qt::black);
        //x = toInt(double(data->highestCorrelationIndex) * ratio);
        x = toInt(double(data->getPeriodEstimatesAt(data->getHighestCorrelationIndex())) * ratio);
        y = toInt(dh2 - highest * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }
      
      //draw a dot at the chosen correlation period
      if(data->getChosenCorrelationIndex() >= 0) {
        p.setPen(Qt::red);
        p.setBrush(Qt::red);
        //x = toInt(double(data->chosenCorrelationIndex) * ratio);
        //y = toInt(dh2 - chosen * dh2);
        x = toInt(double(data->getPeriodEstimatesAt(data->getChosenCorrelationIndex())) * ratio);
        y = toInt(dh2 - data->getPeriodEstimatesAmpAt(data->getChosenCorrelationIndex()) * dh2);
        p.drawEllipse(x-2, y-2, 5, 5);
      }

      //draw a line at the chosen correlation period
      if(data->getChosenCorrelationIndex() >= 0) {
        p.setPen(Qt::green);
        p.setBrush(Qt::green);
        //x = toInt(double(data->periodOctaveEstimate) * ratio);
        x = toInt(double(active->periodOctaveEstimate(chunk)) * ratio);
        p.drawLine(x, 0, x, height());
      }
    }
    
    active->unlock();
    
  }
  endDrawing();
}
Esempio n. 7
0
void VibratoTimeAxis::paintEvent( QPaintEvent * )
{
  beginDrawing(false);

  fillBackground(colorGroup().background());

  doUpdate();

  if (currentChunkToUse >= 0) {
    QFontMetrics fm = p.fontMetrics();
    QString s;
    p.setBrush(Qt::black);
    p.setFont(QFont("AnyStyle", 12));

    int polyLengthInPixels = toInt((endChunkToUse - startChunkToUse) * zoomFactorX);
    float pixelsPerSecond = polyLengthInPixels / noteLengthToUse;
    int notchesDivider = 2;
    double secondsPerNotch = 5;
    int calculationStep = 1;

    // Calculate which notches and labels to draw
    for (int pixelsPerSecondThreshold = 25; ;pixelsPerSecondThreshold *= 2) {
      if (pixelsPerSecond < pixelsPerSecondThreshold) {
        break;
      } else {
        switch (calculationStep) {
          case 1:
            notchesDivider = 5;
            secondsPerNotch /= 5;
            calculationStep = 2;
            break;
          case 2:
            notchesDivider = 2;
            secondsPerNotch = secondsPerNotch;
            calculationStep = 3;
            break;
          case 3:
            notchesDivider = 2;
            secondsPerNotch /= 2;
            calculationStep = 1;
            break;
        }
      }
    }

    // Draw the notches + labels
    for (int i = 0; i < (noteLengthToUse / secondsPerNotch); i++) {
      int x = toInt((((endChunkToUse - startChunkToUse) * zoomFactorX) / noteLengthToUse) * i * secondsPerNotch - windowOffsetToUse);
      if ((x >= 0) && (x < width())) {
        if (i % notchesDivider == 0) {  // Even: bigger notch + label
          p.drawLine(x, height()-6, x, height()-1);
          // The 1.000001 factors in the following statements prevent freaky rounding/floor errors...
          int minutes = intFloor(i*secondsPerNotch*1.000001) / 60;
          int seconds = intFloor(i*secondsPerNotch*1.000001) % 60;
          int thousandthseconds = intFloor(1000*i*secondsPerNotch*1.000001) % 1000;
          if (thousandthseconds == 0) {  // Label: m:ss
            s.sprintf("%1d:%02d", minutes, seconds);
          } else if (thousandthseconds % 100 == 0) {  // Label: m:ss.h
            s.sprintf("%1d:%02d.%01d", minutes, seconds, thousandthseconds / 100);
          } else if (thousandthseconds % 10 == 0) {  // Label: m:ss.hh
            s.sprintf("%1d:%02d.%02d", minutes, seconds, thousandthseconds / 10);
          } else {  // Label: m:ss.hhh
            s.sprintf("%1d:%02d.%03d", minutes, seconds, thousandthseconds);
          }
          p.drawText(x - fm.width(s)/2, 12, s);
          } else {  // Odd: smaller notch
          p.drawLine(x, height()-3, x, height()-1);
        }
      }
    }

    // Draw the horizontal line at the bottom of the axis
    p.drawLine(0, height()-1, width(), height()-1);
  }
  endDrawing();
}
Esempio n. 8
0
void HBlockWidget::paintEvent( QPaintEvent * )
{
  Channel *active = gdata->getActiveChannel();
  
  beginDrawing();
    
  if(active) {
    AnalysisData *theData = active->dataAtCurrentChunk();
    if(theData) {
  
      //get a copy of theData so we don't hold the mutex for too long
      active->lock();
      AnalysisData data = *theData;
      active->unlock();
  
      // We have harmonicFreq - the actual frequencies of the harmonies - and harmonicAmp, their amplitude
      //std::vector<float> harmonicFreq = active->lookup[frame].harmonicFreq;
      std::vector<float> harmonicFreq = data.harmonicFreq;
      // harmonicAmp values range between 0-1
      //std::vector<float> harmonicAmp = active->lookup[frame].harmonicAmp;
      std::vector<float> harmonicAmp = data.harmonicAmp;
  
      // Get the frame's fundamental frequency
      //float fund = active->lookup[frame].fundamentalFreq;
      float fund = data.fundamentalFreq;
  
      // Work out the bar height for each harmonic
      double barHeight = double(height()) / double(harmonicFreq.size());
      QColor fillColor = colorBetween(colorGroup().background(), active->color, data.volumeValue());
      QColor outlineColor = colorBetween(colorGroup().background(), Qt::black, data.volumeValue());
      p.setBrush(fillColor);
  
      int barStart = 0;
      float barWidth = 0;
      int diff = 0;
      /*
      * Each note has a fundamental frequency f, which comes from the lookup table.
      * The harmonic frequencies are defined as f, 2f, 3f, 4f, 5f...
      * harmonicFreq stores what the harmonics have been calculated to be.
      */
      for (uint i = 0; i < harmonicFreq.size(); i++) {
        p.setPen(outlineColor);
        p.setBrush(colorBetween(fillColor, Qt::black, data.harmonicNoise[i]));
        // Work out how many pixels wide the harmonic should be
        barWidth = (harmonicAmp.at(i)) * width();
        /* Work out how many pixels the harmonic should be offset from where it would be
        * if it were exactly (i+1)f   */
        //diff = toInt( (harmonicFreq.at(i) - (i+1) * fund) / fund * width() / 10.0 );
        diff = toInt( (harmonicFreq.at(i) - (i+1) * fund) / fund * barWidth );
        // Work out the starting position, and draw the bar
        barStart = toInt( ((width() / 2) + diff) - barWidth / 2);
	     int barBottom = height() - toInt(barHeight * i);
        p.drawRect(barStart, barBottom, toInt(barWidth), -toInt(barHeight));
        // Draw the centre line on the bar
        p.setPen(Qt::white);
        p.drawLine((width() / 2) + diff, barBottom, (width() / 2) + diff, barBottom - toInt(barHeight));
      }
      // Draw the exact line (f, 2f, 3f...)
      p.setPen(Qt::white);
      p.drawLine(width() / 2, 0, width() /2, height());
    }
  }
  endDrawing();
}