Example #1
0
void RecordNode::filenameComponentChanged(FilenameComponent* fnc)
{

    std::cout << "Got a new file" << std::endl;
    dataDirectory = fnc->getCurrentFile();
    std::cout << "File name: " << dataDirectory.getFullPathName();
    if (dataDirectory.isDirectory())
        std::cout << " is a directory." << std::endl;
    else
        std::cout << " is NOT a directory." << std::endl;

    createNewDirectory();



}
void RecordNode::setParameter(int parameterIndex, float newValue)
{
    //editor->updateParameterButtons(parameterIndex);

    // 0 = stop recording
    // 1 = start recording
    // 2 = toggle individual channel (0.0f = OFF, anything else = ON)

    if (parameterIndex == 1)
    {

		
		// std::cout << "START RECORDING." << std::endl;

        if (newDirectoryNeeded)
        {
            createNewDirectory();
            recordingNumber = 0;
            experimentNumber = 1;
            settingsNeeded = true;
            EVERY_ENGINE->directoryChanged();
        }
        else
        {
            recordingNumber++; // increment recording number within this directory
        }

        if (!rootFolder.exists())
        {
            rootFolder.createDirectory();
        }
        if (settingsNeeded)
        {
            String settingsFileName = rootFolder.getFullPathName() + File::separator + "settings" + ((experimentNumber > 1) ? "_" + String(experimentNumber) : String::empty) + ".xml";
            AccessClass::getEditorViewport()->saveState(File(settingsFileName), m_lastSettingsText);
            settingsNeeded = false;
        }

		m_recordThread->setFileComponents(rootFolder, experimentNumber, recordingNumber);

		channelMap.clear();
		int totChans = channelPointers.size();
		OwnedArray<RecordProcessorInfo> procInfo;
		Array<int> chanProcessorMap;
		Array<int> chanOrderinProc;
		int lastProcessor = -1;
		int procIndex = -1;
		int chanProcOrder = 0;
		for (int ch = 0; ch < totChans; ++ch)
		{
			Channel* chan = channelPointers[ch];
			if (chan->getRecordState())
			{
				channelMap.add(ch);
				//This is bassed on the assumption that all channels from the same processor are added contiguously
				//If this behaviour changes, this check should be most thorough
				if (chan->nodeId != lastProcessor)
				{
					lastProcessor = chan->nodeId;
					RecordProcessorInfo* pi = new RecordProcessorInfo();
					pi->processorId = chan->nodeId;
					procInfo.add(pi);
					procIndex++;
					chanProcOrder = 0;
				}
				procInfo.getLast()->recordedChannels.add(channelMap.size()-1);
				chanProcessorMap.add(procIndex);
				chanOrderinProc.add(chanProcOrder);
				chanProcOrder++;
			}
		}
		std::cout << "Num Recording Processors: " << procInfo.size() << std::endl;
		int numRecordedChannels = channelMap.size();

		//WARNING: If at some point we record at more that one recordEngine at once, we should change this, as using OwnedArrays only works for the first
		EVERY_ENGINE->setChannelMapping(channelMap, chanProcessorMap, chanOrderinProc, procInfo);
		m_recordThread->setChannelMap(channelMap);
		m_dataQueue->setChannels(numRecordedChannels);
		m_eventQueue->reset();
		m_spikeQueue->reset();
		m_recordThread->setFirstBlockFlag(false);

		setFirstBlock = false;
		m_recordThread->startThread();

		isRecording = true;
		hasRecorded = true;

    }
    else if (parameterIndex == 0)
    {


        std::cout << "STOP RECORDING." << std::endl;

        if (isRecording)
        {
			isRecording = false;

            // close the writing thread.
			m_recordThread->signalThreadShouldExit();
			m_recordThread->waitForThreadToExit(2000);
			while (m_recordThread->isThreadRunning())
			{
				std::cerr << "RecordEngine timeout" << std::endl;
				if (AlertWindow::showOkCancelBox(AlertWindow::WarningIcon, "Record Thread timeout",
					"The recording thread is taking too long to close.\nThis could mean there is still data waiting to be written in the buffer, but it normally "
					"shouldn't take this long.\nYou can either wait a bit more or forcefully close the thread. Note that data might be lost or corrupted"
					"if forcibly closing the thread.", "Stop the thread", "Wait a bit more"))
				{
					m_recordThread->stopThread(100);
					m_recordThread->forceCloseFiles();
				}
				else
				{
					m_recordThread->waitForThreadToExit(2000);
				}
			}

        }
    }
    else if (parameterIndex == 2)
    {

        if (isProcessing)
        {

            std::cout << "Toggling channel " << currentChannel << std::endl;

            if (isRecording)
            {
                //Toggling channels while recording isn't allowed. Code shouldn't reach here.
                //In case it does, display an error and exit.
                CoreServices::sendStatusMessage("Toggling record channels while recording is not allowed");
                std::cout << "ERROR: Wrong code section reached\n Toggling record channels while recording is not allowed." << std::endl;
                return;
            }

            if (newValue == 0.0f)
            {
                channelPointers[currentChannel]->setRecordState(false);
            }
            else
            {
                channelPointers[currentChannel]->setRecordState(true);
            }
        }
    }
}
Example #3
0
void RecordNode::setParameter(int parameterIndex, float newValue)
{
    //editor->updateParameterButtons(parameterIndex);

    // 0 = stop recording
    // 1 = start recording
    // 2 = toggle individual channel (0.0f = OFF, anything else = ON)

    if (parameterIndex == 1)
    {

        isRecording = true;
       // std::cout << "START RECORDING." << std::endl;

        if (newDirectoryNeeded)
        {
            createNewDirectory();
            recordingNumber = 0;
        }
        else
        {
            recordingNumber++; // increment recording number within this directory
        }

        if (!rootFolder.exists())
        {
            rootFolder.createDirectory();
            String settingsFileName = rootFolder.getFullPathName() + File::separator + "settings.xml";
            getEditorViewport()->saveState(File(settingsFileName));
        }

        createNewFiles();
        
        openFile(eventChannel);

        blockIndex = 0; // reset index


        // create / open necessary files
        for (int i = 0; i < channelPointers.size(); i++)
        {
           // std::cout << "Checking channel " << i << std::endl;

            if (channelPointers[i]->getRecordState())
            {
                openFile(channelPointers[i]);
            }
        }

        allFilesOpened = true;

    }
    else if (parameterIndex == 0)
    {


       // std::cout << "STOP RECORDING." << std::endl;

        if (isRecording)
        {

            // close necessary files
            signalFilesShouldClose = true;

        }

        isRecording = false;


    }
    else if (parameterIndex == 2)
    {

        if (isProcessing)
        {

            std::cout << "Toggling channel " << currentChannel << std::endl;

            if (newValue == 0.0f)
            {
                channelPointers[currentChannel]->setRecordState(false);

                if (isRecording)
                {

                    if (blockIndex < BLOCK_LENGTH)
                    {
                        // fill out the rest of the current buffer
                        writeContinuousBuffer(zeroBuffer.getReadPointer(0), BLOCK_LENGTH - blockIndex, currentChannel);
                    }

                    closeFile(channelPointers[currentChannel]);
                }

            }
            else
            {
                channelPointers[currentChannel]->setRecordState(true);

                if (isRecording)
                {

                    openFile(channelPointers[currentChannel]);

                    if (blockIndex > 0)
                    {
                        writeTimestampAndSampleCount(channelPointers[currentChannel]->file);
                        // fill up the first data block up to sample count
                        writeContinuousBuffer(zeroBuffer.getReadPointer(0), blockIndex, currentChannel);
                    }

                }
            }
        }
    }
}
Example #4
0
void RecordNode::setParameter(int parameterIndex, float newValue)
{
    //editor->updateParameterButtons(parameterIndex);

    // 0 = stop recording
    // 1 = start recording
    // 2 = toggle individual channel (0.0f = OFF, anything else = ON)

    if (parameterIndex == 1)
    {

        isRecording = true;
        hasRecorded = true;
        // std::cout << "START RECORDING." << std::endl;

        if (newDirectoryNeeded)
        {
            createNewDirectory();
            recordingNumber = 0;
            experimentNumber = 1;
            settingsNeeded = true;
            EVERY_ENGINE->directoryChanged();
        }
        else
        {
            recordingNumber++; // increment recording number within this directory
        }

        if (!rootFolder.exists())
        {
            rootFolder.createDirectory();
        }
        if (settingsNeeded)
        {
            String settingsFileName = rootFolder.getFullPathName() + File::separator + "settings" + ((experimentNumber > 1) ? "_" + String(experimentNumber) : String::empty) + ".xml";
            AccessClass::getEditorViewport()->saveState(File(settingsFileName));
            settingsNeeded = false;
        }

        EVERY_ENGINE->openFiles(rootFolder, experimentNumber, recordingNumber);

        allFilesOpened = true;

    }
    else if (parameterIndex == 0)
    {


        // std::cout << "STOP RECORDING." << std::endl;

        if (isRecording)
        {

            // close necessary files
            signalFilesShouldClose = true;

        }

        isRecording = false;


    }
    else if (parameterIndex == 2)
    {

        if (isProcessing)
        {

            std::cout << "Toggling channel " << currentChannel << std::endl;

            if (isRecording)
            {
                //Toggling channels while recording isn't allowed. Code shouldn't reach here.
                //In case it does, display an error and exit.
                CoreServices::sendStatusMessage("Toggling record channels while recording is not allowed");
                std::cout << "ERROR: Wrong code section reached\n Toggling record channels while recording is not allowed." << std::endl;
                return;
            }

            if (newValue == 0.0f)
            {
                channelPointers[currentChannel]->setRecordState(false);
            }
            else
            {
                channelPointers[currentChannel]->setRecordState(true);
            }
        }
    }
}
Example #5
0
void RecordNode::setParameter(int parameterIndex, float newValue)
{
    //editor->updateParameterButtons(parameterIndex);

    // 0 = stop recording
    // 1 = start recording
    // 2 = toggle individual channel (0.0f = OFF, anything else = ON)

    if (parameterIndex == 1)
    {

		
		// std::cout << "START RECORDING." << std::endl;

        if (newDirectoryNeeded)
        {
            createNewDirectory();
            recordingNumber = 0;
            experimentNumber = 1;
            settingsNeeded = true;
            EVERY_ENGINE->directoryChanged();
        }
        else
        {
            recordingNumber++; // increment recording number within this directory
        }

        if (!rootFolder.exists())
        {
            rootFolder.createDirectory();
        }
        if (settingsNeeded)
        {
            String settingsFileName = rootFolder.getFullPathName() + File::separator + "settings" + ((experimentNumber > 1) ? "_" + String(experimentNumber) : String::empty) + ".xml";
            AccessClass::getEditorViewport()->saveState(File(settingsFileName));
            settingsNeeded = false;
        }

		m_recordThread->setFileComponents(rootFolder, experimentNumber, recordingNumber);

		channelMap.clear();
		int totChans = channelPointers.size();
		for (int ch = 0; ch < totChans; ++ch)
		{
			if (channelPointers[ch]->getRecordState())
			{
				channelMap.add(ch);
			}
		}
		int numRecordedChannels = channelMap.size();

		EVERY_ENGINE->setChannelMapping(channelMap);
		m_recordThread->setChannelMap(channelMap);
		m_dataQueue->setChannels(numRecordedChannels);
		m_eventQueue->reset();
		m_spikeQueue->reset();
		m_recordThread->setFirstBlockFlag(false);

		setFirstBlock = false;
		m_recordThread->startThread();

		isRecording = true;
		hasRecorded = true;

    }
    else if (parameterIndex == 0)
    {


        std::cout << "STOP RECORDING." << std::endl;

        if (isRecording)
        {
			isRecording = false;

            // close the writing thread.
			m_recordThread->signalThreadShouldExit();
			m_recordThread->waitForThreadToExit(2000);
			while (m_recordThread->isThreadRunning())
			{
				std::cerr << "RecordEngine timeout" << std::endl;
				if (AlertWindow::showOkCancelBox(AlertWindow::WarningIcon, "Record Thread timeout",
					"The recording thread is taking too long to close.\nThis could mean there is still data waiting to be written in the buffer, but it normally "
					"shouldn't take this long.\nYou can either wait a bit more or forcefully close the thread. Note that data might be lost or corrupted"
					"if forcibly closing the thread.", "Stop the thread", "Wait a bit more"))
				{
					m_recordThread->stopThread(100);
					m_recordThread->forceCloseFiles();
				}
				else
				{
					m_recordThread->waitForThreadToExit(2000);
				}
			}

        }
    }
    else if (parameterIndex == 2)
    {

        if (isProcessing)
        {

            std::cout << "Toggling channel " << currentChannel << std::endl;

            if (isRecording)
            {
                //Toggling channels while recording isn't allowed. Code shouldn't reach here.
                //In case it does, display an error and exit.
                CoreServices::sendStatusMessage("Toggling record channels while recording is not allowed");
                std::cout << "ERROR: Wrong code section reached\n Toggling record channels while recording is not allowed." << std::endl;
                return;
            }

            if (newValue == 0.0f)
            {
                channelPointers[currentChannel]->setRecordState(false);
            }
            else
            {
                channelPointers[currentChannel]->setRecordState(true);
            }
        }
    }
}