Example #1
0
void Interface::draw() {
    
    ofFill(); 
    ofBackground(0, 0, 0);
    ofSetColor(255);
    
    float w = ofGetWidth();
    float h = ofGetHeight();
            
    // draw settings area 
    
    
    // draw path selector area
    drawPathInspector(0, 0, w*0.5, h*0.5);
    
    // draw map 50% 0, 100%, 60%
    drawMap(w*0.5+pad, 0+pad, (w*0.5)-(2*pad), (h*0.5)-(2*pad));
    
    // draw detail inspection view / path editor 
    drawPointInspector(0, h*0.5, w*0.5, h*0.45);
    
    // draw output view 
    //ofSetColor(60);
    //ofRect(w*0.5, h*0.5, w*0.5, h*0.45);
    drawOutput(w*0.5, h*0.5, w*0.5, h*0.45);
    
    // draw simulator control / timeline
    //ofSetColor(40);
    //ofRect(0, h*0.95, w, h*0.05);
    drawTimeline(0, h*0.95, w, h*0.05);
    
    /*for (int i=0; i<data->paths.size(); i++) {
        drawPath(&data->paths[i]);
    }
    
    if (selectedPoint) {
        drawInterpolation(&selectedPoint->bikes, 20., 800., 700., 400.);
    }*/
    
    
    ofSetColor(20, 20, 255);
    if(selectedPath){
        ofDrawBitmapString("Selected path: " + ofToString(selectedPath->i), 20, 20);
        ofDrawBitmapString("   Sum max: " + ofToString(selectedPath->sum_max), 20, 40);
    }
    if(selectedPoint){
        ofDrawBitmapString("Selected point: " + ofToString(selectedPoint->i), 20, 80);
    }
    if(selectedChannel){
        ofDrawBitmapString("Selected channel: " + ofToString(selectedChannel->i), 20, 140);
    }
    
    ofSetColor(255,20,20);
    ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 20, 180);
    
    
}
Example #2
0
void LfpDisplayCanvas::renderOpenGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // clear buffers to preset values


    //glClear(GL_COLOR_BUFFER_BIT); // clear buffers to preset values

    if (animationIsActive)
        updateScreenBuffer();

    for (int i = 0; i < nChans; i++)
    {
        bool isSelected = false;

        if (selectedChan == i)
            isSelected = true;

        if (checkBounds(i)) {
            //setViewport(i);
            //drawBorder(isSelected);
            drawWaveform(i,isSelected);
            drawChannelInfo(i,isSelected);

        }
    }

    drawScrollBars();

    drawProgressBar();

    drawTimeline();

    // glFlush();
    swapBuffers();

}
Example #3
0
bool wfg_generateImage(char* audioFileName, char* pictureFileName, WFGO* options)
{	
	int width = options->width;
	int height = options->height;
	int seconds;
	long framesPerLine;

	// Initial audio part
	
	SF_INFO sfinfo;
	memset(&sfinfo, 0, sizeof(sfinfo));
	
	SNDFILE *sfile;
	if(audioFileName != NULL) {
		sfile =  sf_open(audioFileName, SFM_READ, &sfinfo);
	} else {
		sfile = sf_open_fd(STDIN_FILENO, SFM_READ, &sfinfo, 0);
	}
	
	if(sfile == NULL)
	{
		lastErrorMessage = "Could not open input file!";
		return false;
	}
	
	if(audioFileName == NULL) {
		seconds = options->trackLength;
		framesPerLine = ((long) seconds * sfinfo.samplerate) / width;
	} else {
		seconds = sfinfo.frames / sfinfo.samplerate;
		framesPerLine = (long) sfinfo.frames / width;
	}
	long samplesPerLine = framesPerLine * sfinfo.channels;
	
	// although one could think, that these values are flexible, the loops
	// below only work in these configurations (1/all or all/1)
	
	int channelsPerDrawing = 1;
	int drawnChannels = sfinfo.channels;
	
	if(options->mixChannels)
	{
		channelsPerDrawing = sfinfo.channels;
		drawnChannels = 1;
	}
		
	float * buffer = malloc(sizeof(float) * samplesPerLine);
	
	// malloc fail
	if(buffer == NULL)
	{
		lastErrorMessage = "Could not allocate memory!";
		sf_close(sfile);
		return false;
	}
	
	// Allocate Image
	gdImagePtr im = gdImageCreate(width,height);
	
	if(im == NULL)
	{
		lastErrorMessage = "Could not allocate image!";
		free(buffer);
		sf_close(sfile);
		return false;
	}
	
	// calculate how large one drawing should be
	
	int drawHeight = height;
	
	// leave space for the timeline
	if(options->drawTimeline)
		drawHeight -= 13;
	
	// subtract spacing
	drawHeight = drawHeight - ((drawnChannels - 1) * options->channelSpacing);
	
	// divide by drawnChannels
	drawHeight = drawHeight / drawnChannels;
	
	// background color
	int bgColor = gdImageColorAllocate(im,WFG_UNPACK_RGB(options->bgColor));
	
	if(options->transparentBg) {
		gdImageColorTransparent(im,bgColor);
	}
	
	int rmsColor =  gdImageColorAllocate(im, WFG_UNPACK_RGB(options->rmsColor));
	int peakColor = gdImageColorAllocate(im, WFG_UNPACK_RGB(options->peakColor));
	
	// too many nested loops ...
	for(int i = 0; i < width; i++)
	{
		if(sf_read_float(sfile, buffer, samplesPerLine) != samplesPerLine)
		{
			if(audioFileName == NULL) {
				memset(buffer, 0, samplesPerLine);
			} else {
				lastErrorMessage = "Could not read samples from audio file!";
				sf_close(sfile);
				free(buffer);
				gdImageDestroy(im);
				return false;
			}
		}
		
		int drawOffset = 0;

		for(int d = 0; d < drawnChannels; d++)
		{
			double val = 0.0;
			
			float peakP = 0.0;
			float peakM = 0.0;
			
			for(long e = 0; e < framesPerLine; e++)
			{
				for(int f = 0; f < channelsPerDrawing; f++)
				{
					float smpl = buffer[e * drawnChannels + d];
					val = val + (smpl*smpl);
					
					if(peakM > smpl)
						peakM = smpl;
					
					if(peakP < smpl)
						peakP = smpl;
				}
			}
			
			val = val / (float) (framesPerLine * channelsPerDrawing);
			val = sqrt(val);
			
			double ddrawHeight = drawHeight;
			
			int peakPP = drawHeight/2 -  round(peakP * (ddrawHeight/2.0));
			int peakMP = drawHeight/2 +  round(peakM * -1.0 * (ddrawHeight/2.0));
					
			// avoid rounding errors when peak is very small
			// if(peakP > 0.001 || peakM < -0.001) 
			gdImageLine(im, i,peakPP + drawOffset,i,peakMP + drawOffset, peakColor);
			
			int rmsSize;
			rmsSize = val * (double) (drawHeight/2);
			gdImageLine(im, i,drawHeight/2 - rmsSize + drawOffset,i,drawHeight/2 + rmsSize + drawOffset, rmsColor);
			
			drawOffset += drawHeight + options->channelSpacing;
		}
	}

	
	sf_close(sfile);
	free(buffer);
	
	if(options->drawTimeline)
		drawTimeline(im, options, seconds);
	
	// write out file
	FILE* file;
	if(pictureFileName) {
		file = fopen(pictureFileName,"wb");
	} else {
		file = stdout;
	}
	if(file == NULL)
	{
		lastErrorMessage = "Could not open output file!";
		gdImageDestroy(im);
	}
	
	gdImagePng(im,file);
	
	fclose(file);
	gdImageDestroy(im);
	
	return true;
}
Example #4
0
void updateUI(void){
    if (currentMenuID == 0 || currentMenuID == 1)
		drawSleep();		
		
	else if (currentMenuID == 10){
		cellsPerFrame = 4;
		drawMainMenu();
	}		
	
	else if (currentMenuID == 11){
		cellsPerFrame = 4;
		drawInavlidResearchPeriod();
	}
		
    else if (currentMenuID == 20 || currentMenuID == 44 || currentMenuID == 54){
		cellsPerFrame = 4;
		drawChooseActivity();
	}		
		
	else if (currentMenuID == 21 || currentMenuID == 45 || currentMenuID == 56){
		cellsPerFrame = 4;
		drawChooseMood();
	}		
		
	else if (currentMenuID == 22 || currentMenuID == 46 || currentMenuID == 55 || currentMenuID == 57 || currentMenuID == 61){
		cellsPerFrame = 4;
		if(currentMenuID == 22)
			drawLogConfirm(LOG);
		else if(currentMenuID == 46)
			drawLogConfirm(ADD);
		else if(currentMenuID == 55 || currentMenuID == 57)
			drawLogConfirm(EDIT);
		else if(currentMenuID == 61)
			drawLogConfirm(REMOVE);
	}		
		
    else if (currentMenuID == 30){
		cellsPerFrame = 2;
		drawTimeline();
	}		
		
    else if (currentMenuID == 40){
		cellsPerFrame = 4;
		drawModifyMenu();
	}
    else if (currentMenuID == 41 || currentMenuID == 50 ||  currentMenuID == 60){
		cellsPerFrame = 2;
		if(currentMenuID == 41)
			drawModifyTimeslot(ADD);
		else if(currentMenuID == 50)
			drawModifyTimeslot(EDIT);
		else if(currentMenuID == 60)
			drawModifyTimeslot(REMOVE);
	}		
		
	else if (currentMenuID == 42 || currentMenuID == 52){
		drawChooseStartTime();
		manipulateTime = NEUTRAL;
	}	

	else if (currentMenuID == 43){
		drawNoRecords();
	}	
		
	else if (currentMenuID == 51)
		drawMoodOrActivity();
	
    else if (currentMenuID == 70)
		drawSettings();
		
    else if (currentMenuID == 71){
		drawChangeTime();
		manipulateTime = NEUTRAL;
	}		
		
    else if (currentMenuID == 72)
		drawInvertColourScheme();

    else if (currentMenuID == 73){
		drawResetRecords(0);
	}

    else if (currentMenuID == 74){
	    drawResetRecords(1);
    }		
		
	else if (currentMenuID == 80)
		drawUpload();
		
}	
Example #5
0
void Timeline::draw(){
    drawCurFrame();
    drawTimeline();
}
Example #6
0
void TracePainter::drawPage(int i, int j)
{
    // Calculate the number of components by vertical
    int from_component = (j == 0) ? 0 : j * components_per_page;
    int to_component = from_component + components_per_page - 1;

    if (to_component >= model->getVisibleComponents().size())
    {
        to_component = model->getVisibleComponents().size() - 1;
    }

    timePerPage = (i > 0) ? timePerFullPage : timePerFirstPage;

    Time min_time = model->getMinTime();
    if (i > 0) min_time = min_time + timePerFirstPage + timePerFullPage * (i - 1);

    Time max_time = min_time + timePerPage;
    if (max_time > model->getMaxTime())
    {
        max_time = model->getMaxTime();
    }

    // FIXME: this temporary change of model is ugly.
    TraceModelPtr saved_model = model;
    model = model->setRange(min_time, max_time);

    if (i == 0)
    {
        left_margin = left_margin1;
    }
    else
    {
        left_margin = left_margin2;
    }

    drawComponentsList(from_component, to_component, i == 0);
    QApplication::processEvents();
    if (state_ == Canceled) return;

    painter->setClipRect(left_margin, y_unparented - lifeline_stepping / 2,
        width - right_margin-left_margin, components_per_page * lifeline_stepping);

    drawEvents(from_component, to_component);
    if (state_ == Canceled) return;

    drawStates(from_component, to_component);
    if (state_ == Canceled) return;

    drawGroups(from_component, to_component);
    if (state_ == Canceled) return;

    if (printer_flag)
    {
        // Draw timeline
        painter->setClipRect(0, 0, width, height);
        drawTimeline(painter, 0, height - (timeline_text_top+text_height));

        // Draw labels with page numbers
        int x, y; QRect r;

        x = 0; y = 0;
        r = drawPageMarker(0, i+1, pages_horizontally, x, y, true);
        x = width - r.width(); y = r.height()/2;
        drawPageMarker(painter, i+1, pages_horizontally, x, y, true);

        x = 0; y = 0;
        r = drawPageMarker(0, j+1, pages_vertically, x, y, false);
        x = r.width()/2; y = height - r.height();
        drawPageMarker(painter, j+1, pages_vertically, x, y, false);

    }

    model = saved_model;
}