예제 #1
0
void dialogAnalog::initPixmap(QSize size)
{
	// resize the pixmap
	//	complete it
	// Draw plot
	QPainter painter;
    int heightPerField = size.height() / NbBits;
	
	lastPixmap=QPixmap( size.width(), size.height() );
	lastPixmap.fill(Qt::black);
	painter.begin(&lastPixmap);
	
    // set font ------------------------------------------------------------------------------------
    QFont textFont;
    textFont.setPixelSize(heightPerField / 2);
    painter.setFont(textFont);

    // set the needed pens -------------------------------------------------------------------------
	QPen linePen(QColor(100,100,100));
    QPen textPen(QColor(255, 255, 255));
    QPen gridPen(QColor(100, 100, 100));
    QColor greenColor(Qt::green);
    QPen dataPen(greenColor);

	// draw the fields and the text ----------------------------------------------------------------
    {
        int current = heightPerField;
        for (int i = 0; i < (NbBits - 1); i++)
        {
            painter.setPen(linePen);
            painter.drawLine(0, current, size.width(), current);
            
            painter.setPen(textPen);
            QString lbl = QString::number(i+1);
            if (currentlabels.contains(i+1)) lbl += "-"+currentlabels[i+1];
            painter.drawText(10, current - heightPerField / 3, lbl);
            current += heightPerField;
        }
        painter.setPen(textPen);
        painter.drawText(10, current - 15, QString::number(NbBits));
    }

	painter.end();
}
예제 #2
0
// ****** Constructor:
AudioVisualizer::AudioVisualizer() : wxFrame((wxFrame *)NULL, -1, wxT("RT-Tuner"), wxDefaultPosition, wxSize(500, 500)) 
{
	// Menus:
	wxMenu *fileMenu = new wxMenu();

	fileMenu->Append(ID_QUIT, wxT("E&xit\tAlt-X"));

	wxMenuBar *menu_bar = new wxMenuBar();
	menu_bar->Append(fileMenu, wxT("&File"));

	SetMenuBar(menu_bar);
	CreateStatusBar(1);
	SetStatusText(wxT(""), 0);

	// Main window:
	wxBoxSizer* windowsizer = new wxBoxSizer(wxVERTICAL);

	// -- Notebook widget
	notebook = new wxNotebook(this, ID_BOOKCTRL, wxDefaultPosition, wxDefaultSize, 0 );
	
	// ---- Spectrum tab
	spectropanel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
	wxBoxSizer* spectrosizer = new wxBoxSizer(wxVERTICAL);

	// ------ initialize the dataLayer vector
	std::vector<double> spectrum;
	std::vector<double> scale;
	dataLayer = new mpFXYVector();
	
	for (size_t i = 0; i < AUDIO_BUFFER_FRAMES; i += 1) {
		spectrum.push_back(0);
		scale.push_back(i);
	}

	dataLayer->SetData(scale, spectrum);
	dataLayer->SetContinuity(true);
	wxPen dataPen(*wxBLUE, 2, wxSOLID);
	dataLayer->SetPen(dataPen);
	dataLayer->SetDrawOutsideMargins(false);
	
	// ------ create and configure the graph
	m_Plot = new mpWindow(spectropanel, -1, wxPoint(0, 0), wxSize(100, 100), wxSUNKEN_BORDER);
	mpScaleX* xaxis = new mpScaleX(wxT("frequency"), mpALIGN_CENTER, TRUE, mpX_NORMAL);
	mpScaleY* yaxis = new mpScaleY(wxT("magnitude"), mpALIGN_CENTER, TRUE);
	m_Plot->AddLayer(xaxis);
	m_Plot->AddLayer(yaxis);
	m_Plot->AddLayer(dataLayer);
	m_Plot->EnableDoubleBuffer(true);
	m_Plot->EnableMousePanZoom(false);
	m_Plot->SetMPScrollbars(false);
	m_Plot->Fit();

	// ------ create the log window
	m_Log = new wxTextCtrl(spectropanel, -1, wxT("---Program started---\n"), wxPoint(0, 0), wxSize(100, 100), wxTE_MULTILINE);
	wxLog *old_log = wxLog::SetActiveTarget(new wxLogTextCtrl(m_Log));
	delete old_log;

	// ------ (layout organization)
	spectrosizer->Add(m_Plot, 1, wxALL | wxEXPAND, 5);
	spectrosizer->Add(m_Log, 0, wxALL | wxEXPAND, 5);

	spectropanel->SetSizer(spectrosizer);
	spectropanel->Layout();
	spectrosizer->Fit(spectropanel);
	
	notebook->AddPage(spectropanel, wxT("Spectrum"), true);

	// ---- Tuner tab
	tunerpanel = new wxPanel(notebook);
	wxBoxSizer* tunersizer = new wxBoxSizer(wxVERTICAL);

	// ------ configure the needle gauge and text labels
	AudioVisualizer::SetUpAngularMeter(tunerpanel);
	m_FreqText = new wxStaticText(tunerpanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_CENTER | wxTE_MULTILINE);
	m_NoteText = new wxStaticText(tunerpanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_CENTER | wxTE_MULTILINE);
	
	// ------ (layout organization)
	tunersizer->Add(m_AngularMeter, 0, wxALIGN_CENTER_HORIZONTAL);
	tunersizer->Add(m_FreqText, 1, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
	tunersizer->Add(m_NoteText, 1, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
	
	tunerpanel->SetSizer(tunersizer);
	tunerpanel->Layout();
	tunersizer->Fit(tunerpanel);
	
	notebook->AddPage(tunerpanel, wxT("Tuner"), false);

	windowsizer->Add(notebook, 1, wxEXPAND | wxALL, 5);

	// -- Start/stop button
	startstopButton = new wxButton(this, ID_STARTSTOP_BUTTON, wxT("&Stop"), wxDefaultPosition, wxDefaultSize, 0);
	startstopButton->Enable(true);
	
	// ----(layout organization)
	windowsizer->Add(startstopButton, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
	this->SetSizer(windowsizer);
	this->Layout();
	this->Centre(wxBOTH);
	this->RefreshWindow();

	// -- Timer
	m_timer = new wxTimer(this, ID_REFRESH_TIMER);
	m_timer->Start(REFRESH_INTERVAL);

	// initialize audio capturer
	capturer = new AudioCapturer(this->dataLayer, &this->totalfreq, &this->freqcount);
	this->running = true;	// indicate that the audio function is running

}