void AnalysisView::savePressed() {
	std::list<std::pair<std::string, int64_t> > markers;

	const int upperthresh = _audioView->upperThresh();
	const int lowerthresh = _audioView->lowerThresh();

	for(unsigned int i = 0; i < _spikes.spikes().size(); i++)
		if(_spikes.spikes()[i].second > lowerthresh && _spikes.spikes()[i].second < upperthresh)
			markers.push_back(std::make_pair(std::string("_neuron1"), _spikes.spikes()[i].first));

	FileRecorder f(_manager);
	std::string filename = f.eventTxtFilename(_manager.fileName());

	f.writeMarkerTextFile(filename, markers);
	std::stringstream s;
	s << markers.size() << " spikes were written to '" << filename << "'";
	Widgets::ErrorBox *box = new Widgets::ErrorBox(s.str().c_str());
	box->setGeometry(Widgets::Rect(this->width()/2-200, this->height()/2-40, 400, 80));
	Widgets::Application::getInstance()->addPopup(box);
}
//
// Connect/dsconnect from serial port
//
void ConfigView::connectPressed()
{
    if(_manager.serialMode())
    {
        _manager.setSerialNumberOfChannels(1);
        _manager.disconnectFromSerial();
        
    }
    else
    {
        if(!_manager.initSerial(serialPortWidget->item(serialPortWidget->selection()).c_str()))
        {
	    Log::error("Can't init serial port.");
	    const char *error = _manager.serialError.c_str();
	    if(strlen(error) == 0) {
		    error = "Error: Cannot init serial port.";
	    }            

            Widgets::ErrorBox *box = new Widgets::ErrorBox(error);
            box->setGeometry(Widgets::Rect(this->width()/2-250, this->height()/2-40, 500, 80));
            Widgets::Application::getInstance()->addPopup(box);
        }
    }
    if(_manager.serialMode())
    {
        _connectButton->setNormalTex(Widgets::TextureGL::get("data/connected.png"));
        _connectButton->setHoverTex(Widgets::TextureGL::get("data/connected.png"));
        close();
    }
    else
    {
        _connectButton->setNormalTex(Widgets::TextureGL::get("data/disconnected.png"));
        _connectButton->setHoverTex(Widgets::TextureGL::get("data/disconnected.png"));
        close();
        
    }
    serialPortWidget->setDisabled(_manager.serialMode());
}
void ConfigView::colorChanged(int virtualDevice, int coloridx) {
	int channel = _audioView.virtualDeviceChannel(virtualDevice);
	if(channel < 0 && coloridx != 0) {
		int nchan = _audioView.addChannel(virtualDevice);
		if(nchan != -1) {
			_audioView.setChannelColor(nchan, coloridx);
		} else {
			_clrs[virtualDevice]->setSelectionSilent(0);

			std::stringstream s;
			s << "Error: Cannot open channel";
			if(BASS_ErrorGetCode())
				s << ": " << GetBassStrError();
			Widgets::ErrorBox *box = new Widgets::ErrorBox(s.str().c_str());
			box->setGeometry(Widgets::Rect(this->width()/2-200, this->height()/2-40, 400, 80));
			Widgets::Application::getInstance()->addPopup(box);
		}
	} else if(coloridx == 0) {
		_audioView.removeChannel(virtualDevice);
	} else {
		_audioView.setChannelColor(channel, coloridx);
	}
}