Ejemplo n.º 1
0
void StackDisplay::paintEvent(QPaintEvent *)
{
    drawBars();
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Ejemplo n.º 2
0
void BarChartWidget::paintEvent(QPaintEvent *event) {
    QWidget::paintEvent(event);

    QPainter painter(this);

    drawLabel(painter);
    drawBaseLine(painter);
    drawBars(painter);
}
Ejemplo n.º 3
0
void CIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    drawVariables(painter);
    drawBackground(painter);
    drawLCDNums(painter);
    drawRect(painter);
    drawGraph(painter);
    drawBars(painter);
}
Ejemplo n.º 4
0
	/**
	 * Graph::draw,	render whole scene.
	 */
	void Graph::draw()
	{
		static int cnt = 0;
		cnt++;

		glViewport((int)mViewPos.x, (int)mViewPos.y, mWidth, mHeight);
		checkGLError("glViewport");
		mDeltaTime.tick();

		float tick = static_cast<float>(mTime.update()) * 0.001f;
		mScene.setElapsedTime(tick);

		// Clear the color buffer
		glClearColor(mBGColor.r,mBGColor.g,mBGColor.b, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		checkGLError("glClear");

		mTouch.update();
		mScene.updateCamera(mTouch.getScale());

		// working with angular speed
		const glm::vec3 rotSpeed = mTouch.getAngularSpeed();
		glm::vec3 axisY(0.0f,1.0f,0.0f);
		glm::mat4 mY = glm::rotate(rotSpeed.x*30.0f,axisY);
		glm::vec3 axisX(1.0f,0.0f,0.0f);
		glm::mat4 mX = glm::rotate(rotSpeed.y*30.0f,axisX);
		glm::vec3 axisZ(0.0f,0.0f,1.0f);
		glm::mat4 mZ = glm::rotate(rotSpeed.z*30.0f,axisZ);
		glm::mat4 mW = mScene.getWorldMat();
		glm::mat4 m = mZ*mY*mX*mW;
		mScene.setWorldMat( m );
		mScene.updateMatrix();		// need to update the PVW Matrix, Projection * View * World.

		glEnable(GL_DEPTH_TEST);

		drawBars(tick);
		drawAxis(tick);
		drawText(tick);

	}
Ejemplo n.º 5
0
int main(int argc, char* argv[]){
    SDL_Surface *screen = NULL;

    SDL_Event event;

    SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO);
	//screen = SDL_SetVideoMode(512, 320, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
    screen = SDL_SetVideoMode(1024, 640, 32, SDL_SWSURFACE | SDL_DOUBLEBUF /*| SDL_HWSURFACE*/);
	//screen = SDL_SetVideoMode(1920, 1080, 32, SDL_SWSURFACE | SDL_DOUBLEBUF |SDL_FULLSCREEN);

    printf("FFT WavViz by Caiwan^IR \r\n");

    FILE *fp = stdin;

	int isReadFromStdin = 0;

    if (argc>1){
        fp = fopen(argv[1],"rb");
        if (!fp) {
            printf("No such file");
            return 1;
        }
        printf("Loading input stream from file\r\n");
		isReadFromStdin = 0;
    } else {
        printf("Awaiting input stream from stdin\r\n");
		isReadFromStdin = 1;
    }

    try{
		Timer* timer = new Timer();
        WavRead *reader = new WavRead(fp);

		SDL_Rect pos1, pos2;
		//unsigned char *spectogram1 = NULL, *spectogram2 = NULL;
		struct spectogram_object_t *spectogram1 = NULL, *spectogram2 = NULL;
		struct spectrum_object_t   *spectrum1 = NULL, *spectrum2 = NULL;
		if (reader->getChannels() == 2){
			pos1.x = 0; pos1.y = 0;
			pos1.w = 100; pos1.h = 43;

			pos2.x = 0; pos2.y = 46;
			pos2.w = 100; pos2.h = 43;
			
			spectrum2 = initDrawBars(pos2, reader->getSamplingFreq(), FFT_SAMPLE, NULL, screen);

			//spectogram2 = initDrawSpectogram(pos2.x, pos2.y, pos2.w, pos2.h, spectogram2, screen);
		} else {
			pos1.x = 0; pos1.y = 0;
			pos1.w = 100; pos1.h = 70;
		}

		spectrum1 = initDrawBars(pos1, reader->getSamplingFreq(), FFT_SAMPLE, NULL, screen);
		//spectogram1 = initDrawSpectogram(pos1.x, pos1.y, pos1.w, pos1.h, spectogram1, screen);


		//reader->fillBuffer();
        WavPlayer::InitAudio(reader);

        FFT32* fft = new FFT32(FFT_SAMPLE, reader->getSamplingFreq());

		WavPlayer::PlayAudio();

        bool running = true;
		unsigned int dtime = timer->getDeltaTimeMs(), ttime = 0, frame = 0, frametime = 0, frameskip = 0;
		unsigned int btime = 0, s1time = 0, s2time = 0;

		int offset = 0, getnext = 1;

		int *fft_buffer[2];
		fft_buffer[0]= new int[2*AUDIO_BUFFER_LEN];
		if (reader->getChannels() == 2) fft_buffer[1] = new int[2*AUDIO_BUFFER_LEN]; else fft_buffer[1] = NULL;

        SDL_Event event;

        while (running) {
            try {
				if (reader->isBufferChanged()){ 
					btime = 0; getnext = 1;
				} else { 
					btime += dtime; getnext = 0;
				}

				offset = btime * reader->getSamplingFreq() / 1000;

				if (offset>AUDIO_BUFFER_LEN) 
					throw 115;

				//if (offset<0) throw 1;

                if (reader->getChannels() == 2){
					//if (getnext) reader->fillBufferComplex(fft_buffer[0], WavRead::CH_LEFT);
					if (getnext) reader->fillBufferComplex(fft_buffer[0], WavRead::CH_LEFT);
					fft->calculate(&fft_buffer[0][offset]);

                    //drawBars(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, 0, 85, 49, 15, screen);
					drawBars(fft->getLastResult(), spectrum1, screen);
					//s1time = drawSpectogram(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, pos1.x, pos1.y, pos1.w, pos1.h, spectogram1, s1time, screen);

					///
					if (getnext) reader->fillBufferComplex(fft_buffer[1], WavRead::CH_RIGHT);
					fft->calculate(&fft_buffer[1][offset]);

                    //drawBars(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, 51, 85, 49, 15, screen);
					drawBars(fft->getLastResult(), spectrum2, screen);
					//s2time = drawSpectogram(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, pos2.x, pos2.y, pos2.w, pos2.h, spectogram1, s2time, screen);

					getnext = 0;
                } else {
					if (getnext) reader->fillBufferComplex(fft_buffer[0], WavRead::CH_MONO);
                    fft->calculate(&fft_buffer[0][offset]);
                    //drawBars(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, 0, 85, 100, 15, screen);
					//s1time = drawSpectogram(fft->getLastResult(), reader->getSamplingFreq(), FFT_SAMPLE, pos1.x, pos1.y, pos1.w, pos1.h, spectogram1, s1time, screen);
					getnext = 0;
                }

            } catch (int e){
                // egyes esetekben lemarad a bufferrol, ezert el kell dobni 1-1 framet emiatt sajnos.
                if (e == 14 || e == 11 || e ==115)
                    frameskip ++ ;
                else throw e;
            }

            SDL_Flip(screen);

			//if(!isReadFromStdin){
			running = !reader->isEndOfStream();
			//}
			ttime += dtime = timer->getDeltaTimeMs();
			printf("time: %d.%d                 \r", ttime/1000, ttime%1000);

			// FRAPS!
			if (frametime>=1000){
				printf("FPS: %d skipped: %d                \r\n", frame, frameskip);
				frameskip = 0;
				frametime = 0;
				frame = 0;
			} else {
				frametime += dtime;
				frame++;
			}

            while (SDL_PollEvent(&event)) {
				/* GLOBAL KEYS / EVENTS */
                switch (event.type) {
                case SDL_KEYDOWN:
                    switch (event.key.keysym.sym) {
                    case SDLK_ESCAPE:
                        running &= false;
                        break;
                    default: break;
                    }
                    break;
                case SDL_QUIT:
                    running &= false;
                    break;
                }
            }
        }

        WavPlayer::DestroyAudio();

        if (reader) delete reader;
		if (timer) delete timer;
		if (fft) delete fft;

		if (fft_buffer[0]) delete fft_buffer[0];
		if (fft_buffer[1]) delete fft_buffer[1];

    } catch (int e){
        printf("Could not open file. Error code: %d\r\n",e);
    }

    fclose(fp);

    return 0;
}
Ejemplo n.º 6
0
void tGraph::draw(QPainter & paint) {
    //QPainter paint(this);
    paint.save();

    int gx1 = hPadding() + _rect.x();
    int gy1 = vPadding() + _rect.y();
    int gx2 = _rect.x() + width() - hPadding();
    int gy2 = _rect.y() + height() - vPadding();

    //paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);

    QFontMetrics fm(font());
    //QRect brect;

    // get the dimensions of the title label and then draw it
    if(title().length() > 0) {
        fm = QFontMetrics(titleFont());
        //brect = fm.boundingRect(title());
        paint.setFont(titleFont());
        paint.drawText(gx1, gy1, gx2 - gx1, fm.height(), titleAlignment(), title());
        gy1 += fm.height();
    }

    // we need to do some drawing that depends on some other elements having
    // already been placed... since those require that these have already been
    // placed we will just save the old value of gy2 and then calculate the
    // value that we should have after the other code runs without actually
    // drawing anything right now
    int gy2_old = gy2;
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        gy2 -= fm.height();
    }
    fm = QFontMetrics(dataFont());
    QMapIterator<int, GReference> dlit = _data.begin();
    double tlh = 0.0;
    for(dlit = _data.begin(); dlit != _data.end(); ++dlit) {
        tlh = QMAX(sin45deg * fm.width(dlit.data().first), tlh);
    }
    // don't change this variable as we use it later
    int th = (tlh == 0.0 ? 0 : (int)(tlh + (fm.height() * sin45deg)) + 2);
    gy2 -= th;


    // get the dimensions of the value label then draw it
    if(valueLabel().length() > 0) {
        fm = QFontMetrics(valueLabelFont());
        //brect = fm.boundingRect(valueLabel());
        paint.setFont(valueLabelFont());
        paint.save();
        paint.rotate(-90);
        paint.drawText(-gy2, gx1, gy2 - gy1, fm.height(), valueLabelAlignment(), valueLabel());
        paint.restore();
        gx1 += fm.height();
    }

    fm = QFontMetrics(valueFont());

    QString min_str = QString().sprintf("%-.0f",minValue());
    QString org_str = ( minValue() == 0.0 ? QString::null : "0" );
    QString max_str = QString().sprintf("%-.0f",maxValue());

    int width = QMAX(fm.width(min_str), fm.width(max_str));
    if(org_str.length() > 0) width = QMAX(width, fm.width(org_str));

    gx1 += width;

    int gy_max = gy1;
    int gy_min = gy2 - 1;
    int gy_org = gy_min;

    paint.setFont(valueFont());
    int tfa = Qt::AlignTop | Qt::AlignRight;
    paint.drawText(gx1 - fm.width(min_str), gy_min, fm.width(min_str), fm.height(), tfa, min_str);
    paint.drawLine(gx1 - 3, gy_min, gx1 + 2, gy_min);
    paint.drawText(gx1 - fm.width(max_str), gy_max, fm.width(max_str), fm.height(), tfa, max_str);
    paint.drawLine(gx1 - 3, gy_max, gx1 + 2, gy_max);
    int gheight = gy2 - gy1;
    double grng = maxValue() - minValue();
    if(org_str.length() > 0) {
        double perc = (0 - minValue()) / grng;
        gy_org = gy2 - (int)(perc * (double)gheight);
        paint.drawText(gx1 - fm.width(org_str), gy_org, fm.width(org_str), fm.height(), tfa, org_str);
        paint.drawLine(gx1 - 3, gy_org, gx1 + 2, gy_org);
    }

    gx1 += 3;

    // put the old value back so all the code to come draw correctly!
    gy2 = gy2_old;

    // get the dimensions of the data label then draw it
    if(dataLabel().length() > 0) {
        fm = QFontMetrics(dataLabelFont());
        //brect = fm.boundingRect(dataLabel());
        paint.setFont(dataLabelFont());
        gy2 -= fm.height();
        paint.drawText(gx1, gy2, gx2 - gx1, fm.height(), dataLabelAlignment(), dataLabel());
    }

    gy2 -= th;

    int ref_cnt = _data.count();
    int gwidth = gx2 - gx1;
    gheight = gy2 - gy1;

    if(ref_cnt > 0) {
        paint.save();
        fm = QFontMetrics(dataFont());
        paint.setFont(dataFont());
        int refwidth = QMAX(1, gwidth / ref_cnt);
        int buf = (int)(refwidth / 5);
        int buf2 = buf * 2;
        QMapIterator<int, GReference> rit;
        int pos = gx1 + (int)((gwidth - (refwidth * ref_cnt)) / 2);
        int bar_height;
        int fmheight = fm.height();
        int fmheight_div_2 = fmheight / 2;
        int refwidth_div_2 = refwidth / 2;
        int label_offset = (int)(fmheight_div_2 * cos45deg);
        int last_label_at = -1000;
        QMap<int, double> last_map;
        QMap<int, double> this_map;
        for(rit = _data.begin(); rit != _data.end(); ++rit ) {
            GReference ref = rit.data();
            QString label = ref.first;
            if(label.length() > 0 && ((pos + refwidth_div_2) - last_label_at) > ((label_offset * 2) + 1)) {
                last_label_at = pos + refwidth_div_2;
                int lx = (int)(((pos + refwidth_div_2) * cos45deg) - ((gy2 + label_offset) * sin45deg));
                int ly = (int)(((pos + refwidth_div_2) * sin45deg) + ((gy2 + label_offset) * cos45deg));
                int fmwidth = fm.width(label);
                paint.save();
                paint.rotate(-45);
                paint.drawText(lx - fmwidth, ly - fmheight_div_2, fmwidth, fmheight, Qt::AlignRight | Qt::AlignTop, label);
                paint.restore();
            }

            QMapIterator<int, double> sit;
            paint.save();
            if(drawBars() == TRUE) {
                TSetValue tval;
                QMap<double, TSetValue> sort_map;
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit ) {
                    if(sit.data() != 0.0 && _setStyle[sit.key()].bar == TRUE) {
                        tval.first = sit.key();
                        tval.second = sit.data();
                        sort_map[(tval.second < 0.0 ? minValue() : maxValue()) - (tval.second < 0.0 ? -tval.second : tval.second)] = tval;
                    }
                }
                QMapIterator<double, TSetValue> it;
                for(it = sort_map.begin(); it != sort_map.end(); ++it) {
                    tval = it.data();
                    if(tval.second != 0.0) {
                        if(tval.second < 0) {
                            bar_height = (int)((tval.second / minValue()) * (gy_org - gy_min));
                        } else {
                            bar_height = (int)((tval.second / maxValue()) * (gy_org - gy_max));
                        } 
                        paint.fillRect(pos + buf, gy_org - bar_height, refwidth - buf2, bar_height, getSetColor(tval.first));
                    }
                }
            }
            if(drawLines() == TRUE) {
                this_map.clear();
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    if(_setStyle[sit.key()].line == TRUE) {
                        this_map[sit.key()] = sit.data();
                        if(last_map.contains(sit.key())) {
                            paint.setPen(getSetColor(sit.key()));
                            double old_val = last_map[sit.key()];
                            double new_val = sit.data();
                            int ly1;
                            if(old_val < 0.0) ly1 = (int)((old_val / minValue()) * (gy_org - gy_min));
                            else              ly1 = (int)((old_val / maxValue()) * (gy_org - gy_max));
                            ly1 = gy_org - ly1;
                            int lx1 = pos - refwidth_div_2;
                            int ly2;
                            if(new_val < 0.0) ly2 = (int)((new_val / minValue()) * (gy_org - gy_min));
                            else              ly2 = (int)((new_val / maxValue()) * (gy_org - gy_max));
                            ly2 = gy_org - ly2;
                            int lx2 = pos + refwidth_div_2;
                            paint.drawLine(lx1, ly1, lx2, ly2);
                        }
                    }
                }
                last_map = this_map;
            }
            if(drawPoints() == TRUE) {
                for(sit = ref.second.begin(); sit != ref.second.end(); ++sit) {
                    if(_setStyle[sit.key()].point == TRUE) {
                        paint.setBrush(getSetColor(sit.key()));
                        paint.setPen(QColor(0,0,0));
                        int ly1;
                        if(sit.data() < 0.0) ly1 = (int)((sit.data() / minValue()) * (gy_org - gy_min));
                        else                 ly1 = (int)((sit.data() / maxValue()) * (gy_org - gy_max));
                        ly1 = gy_org - ly1;
                        int lx1 = pos + refwidth_div_2;
                        paint.drawEllipse(lx1 - 2, ly1 - 2, 5, 5);
                    }
                }
            }
            paint.restore();
            pos += refwidth;
        }
        paint.restore();
    }

    paint.drawLine(gx1, gy_org, gx2 - 1, gy_org);
    paint.drawRect(gx1, gy1, gx2 - gx1, gy2 - gy1);


    // Now that we are done return the paint device back to the state
    // it was when we started to mess with it
    paint.restore();
}
Ejemplo n.º 7
0
/**
 * Update thread which do the rendering
 * @param p_this: the p_thread object
 */
static void *Thread( void *p_data )
{
    filter_t  *p_filter = (filter_t*)p_data;
    filter_sys_t *p_sys = p_filter->p_sys;

    video_format_t fmt;
    vlc_gl_t *gl;
    unsigned int i_last_width = 0;
    unsigned int i_last_height = 0;

    /* Create the openGL provider */
    p_sys->p_vout =
        (vout_thread_t *)vlc_object_create(p_filter, sizeof(vout_thread_t));
    if (!p_sys->p_vout)
        goto error;

    /* Configure the video format for the opengl provider. */
    video_format_Init(&fmt, 0);
    video_format_Setup(&fmt, VLC_CODEC_RGB32,
                       p_sys->i_width, p_sys->i_height, 0, 1 );
    fmt.i_sar_num = 1;
    fmt.i_sar_den = 1;

    /* Init vout state. */
    vout_display_state_t state;
    memset(&state, 0, sizeof(state));
    state.cfg.display.sar.num = 1;
    state.cfg.display.sar.den = 1;
    state.cfg.is_display_filled = true;
    state.cfg.zoom.num = 1;
    state.cfg.zoom.den = 1;
    state.sar.num = 1;
    state.sar.den = 1;

    p_sys->p_vd = vout_NewDisplay(p_sys->p_vout, &fmt, &state,
                                  "opengl", 1000000, 1000000);
    if (!p_sys->p_vd)
    {
        vlc_object_release(p_sys->p_vout);
        goto error;
    }

    gl = vout_GetDisplayOpengl(p_sys->p_vd);
    if (!gl)
    {
        vout_DeleteDisplay(p_sys->p_vd, NULL);
        vlc_object_release(p_sys->p_vout);
        goto error;
    }

    vlc_sem_post(&p_sys->ready);

    initOpenGLScene();

    float height[NB_BANDS] = {0};

    while (1)
    {
        block_t *block = block_FifoGet(p_sys->fifo);

        int canc = vlc_savecancel();

        /* Manage the events */
        vout_ManageDisplay(p_sys->p_vd, true);
        if (p_sys->p_vd->cfg->display.width != i_last_width ||
            p_sys->p_vd->cfg->display.height != i_last_height)
        {
            /* FIXME it is not perfect as we will have black bands */
            vout_display_place_t place;
            vout_display_PlacePicture(&place, &p_sys->p_vd->source,
                                      p_sys->p_vd->cfg, false);

            i_last_width  = p_sys->p_vd->cfg->display.width;
            i_last_height = p_sys->p_vd->cfg->display.height;
        }

        /* Horizontal scale for 20-band equalizer */
        const unsigned xscale[] = {0,1,2,3,4,5,6,7,8,11,15,20,27,
                                   36,47,62,82,107,141,184,255};

        fft_state *p_state; /* internal FFT data */

        unsigned i, j;
        float p_output[FFT_BUFFER_SIZE];           /* Raw FFT Result  */
        int16_t p_buffer1[FFT_BUFFER_SIZE];        /* Buffer on which we perform
                                                      the FFT (first channel) */
        int16_t p_dest[FFT_BUFFER_SIZE];           /* Adapted FFT result */
        float *p_buffl = (float*)block->p_buffer;  /* Original buffer */

        int16_t  *p_buffs;                         /* int16_t converted buffer */
        int16_t  *p_s16_buff;                      /* int16_t converted buffer */

        /* Allocate the buffer only if the number of samples change */
        if (block->i_nb_samples != p_sys->i_prev_nb_samples)
        {
            free(p_sys->p_prev_s16_buff);
            p_sys->p_prev_s16_buff = malloc(block->i_nb_samples *
                                            p_sys->i_channels *
                                            sizeof(int16_t));
            if (!p_sys->p_prev_s16_buff)
                goto release;
            p_sys->i_prev_nb_samples = block->i_nb_samples;
        }
        p_buffs = p_s16_buff = p_sys->p_prev_s16_buff;

        /* Convert the buffer to int16_t
           Pasted from float32tos16.c */
        for (i = block->i_nb_samples * p_sys->i_channels; i--;)
        {
            union {float f; int32_t i;} u;

            u.f = *p_buffl + 384.0;
            if (u.i > 0x43c07fff)
                *p_buffs = 32767;
            else if (u.i < 0x43bf8000)
                *p_buffs = -32768;
            else
                *p_buffs = u.i - 0x43c00000;

            p_buffl++; p_buffs++;
        }
        p_state = visual_fft_init();
        if (!p_state)
        {
            msg_Err(p_filter,"unable to initialize FFT transform");
            goto release;
        }
        p_buffs = p_s16_buff;
        for (i = 0 ; i < FFT_BUFFER_SIZE; i++)
        {
            p_output[i] = 0;
            p_buffer1[i] = *p_buffs;

            p_buffs += p_sys->i_channels;
            if (p_buffs >= &p_s16_buff[block->i_nb_samples * p_sys->i_channels])
                p_buffs = p_s16_buff;
        }
        fft_perform (p_buffer1, p_output, p_state);

        for (i = 0; i< FFT_BUFFER_SIZE; ++i)
            p_dest[i] = p_output[i] *  (2 ^ 16)
                        / ((FFT_BUFFER_SIZE / 2 * 32768) ^ 2);

        for (i = 0 ; i < NB_BANDS; i++)
        {
            /* Decrease the previous size of the bar. */
            height[i] -= BAR_DECREMENT;
            if (height[i] < 0)
                height[i] = 0;

            int y = 0;
            /* We search the maximum on one scale
               to determine the current size of the bar. */
            for (j = xscale[i]; j < xscale[i + 1]; j++)
            {
                if (p_dest[j] > y)
                     y = p_dest[j];
            }
            /* Calculate the height of the bar */
            float new_height = y != 0 ? log(y) * 0.4 : 0;
            height[i] = new_height > height[i]
                        ? new_height : height[i];
        }

        /* Determine the camera rotation angle. */
        p_sys->f_rotationAngle += p_sys->f_rotationIncrement;
        if (p_sys->f_rotationAngle <= -ROTATION_MAX)
            p_sys->f_rotationIncrement = ROTATION_INCREMENT;
        else if (p_sys->f_rotationAngle >= ROTATION_MAX)
            p_sys->f_rotationIncrement = -ROTATION_INCREMENT;

        /* Render the frame. */
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();
            glRotatef(p_sys->f_rotationAngle, 0, 1, 0);
            drawBars(height);
        glPopMatrix();

        /* Wait to swapp the frame on time. */
        mwait(block->i_pts + (block->i_length / 2));
        if (!vlc_gl_Lock(gl))
        {
            vlc_gl_Swap(gl);
            vlc_gl_Unlock(gl);
        }

release:
        block_Release(block);
        vlc_restorecancel(canc);
    }

    assert(0);

error:
    p_sys->b_error = true;
    vlc_sem_post(&p_sys->ready);
    return NULL;
}
Ejemplo n.º 8
0
void BeerStatsFrame::drawContent(QPainter &painter, int panel, int offset)
{
    vector<QStringDoublePair> pairs;

    switch(panel)
    {
        case 0: // today's pours
        {
            drawHeader(painter, QString("today's pours"), offset);

            map<User*, int> userPours;
            vector<Pour*> pours = Pour::PoursByKegId[CurrentKeg->Id];
            double now = time(NULL);
            for (int i=0; i<pours.size(); i++)
            {
                Pour* pour = pours[i];
                if (now - pour->Time >= 0.5 * Constants::Day)
                    continue;
                User* user = User::UsersById[pour->UserId];
                userPours[user]++;
            }

            map<User*, int>::iterator iter;
            for (iter = userPours.begin(); iter != userPours.end(); iter++)
                pairs.push_back(QStringDoublePair(QString(iter->first->Name.c_str()),iter->second));


            if (pairs.size() == 0)
                drawNone(painter, QString("none"), offset);
            else
                drawTiles(painter, pairs, offset);
        }
        break;
        case 1: //pours by day
        {
            drawHeader(painter, QString("pours by day"), offset);

            // DOW of week pours
            vector<int> dowPours = Pour::GetPoursByDow(CurrentKeg);
            //int dowPours[] = {22, 5, 12, 13, 11, 24, 20};
            int maxDowPours = 0;
            for (int i=0; i<7; i++)
                maxDowPours = max(dowPours[i], maxDowPours);

            for (int i=0; i<7; i++)
                pairs.push_back(QStringDoublePair(dowNames[i],dowPours[i]/(double)maxDowPours));

            if (maxDowPours == 0)
                drawNone(painter, QString("none"), offset);

            drawBars(painter, pairs, offset);
        }
        break;
        case 2: // pours by user
        {
            drawHeader(painter, QString("pours by user"), offset);

            if (CurrentKeg == NULL)
            {
                drawNone(painter, QString("none"), offset);
                return;
            }

            map<User*, int> userPours = Pour::GetPoursByUser(CurrentKeg);
            int maxPours = 0;
            map<User*, int>::iterator iter;
            for (iter = userPours.begin(); iter != userPours.end(); iter++)
                maxPours = max(maxPours, iter->second);

            for (iter = userPours.begin(); iter != userPours.end(); iter++)
                pairs.push_back(QStringDoublePair(QString(iter->first->Name.c_str()),iter->second/(double)maxPours));

            if (maxPours == 0)
                drawNone(painter, QString("none"), offset);
            else
                drawBars(painter, pairs, offset);
        }
        break;
    }
}