diff --git a/Source/Processors/FileReader/FileReader.cpp b/Source/Processors/FileReader/FileReader.cpp index 31c0ed0d25003a5d4283813f313880f616a89fff..fd8b01a1abeb747bbacb98767df2988d03a88553 100644 --- a/Source/Processors/FileReader/FileReader.cpp +++ b/Source/Processors/FileReader/FileReader.cpp @@ -67,25 +67,25 @@ bool FileReader::isReady() float FileReader::getDefaultSampleRate() { if (input) - return currentSampleRate; - else - return 44100.0; + return currentSampleRate; + else + return 44100.0; } int FileReader::getDefaultNumOutputs() { - if (input) - return currentNumChannels; - else - return 16; + if (input) + return currentNumChannels; + else + return 16; } float FileReader::getBitVolts(int chan) { - if (input) - return channelInfo[chan].bitVolts; - else - return 0.05f; + if (input) + return channelInfo[chan].bitVolts; + else + return 0.05f; } void FileReader::enabledState(bool t) @@ -98,71 +98,71 @@ void FileReader::enabledState(bool t) bool FileReader::setFile(String fullpath) { - File file(fullpath); - - String ext = file.getFileExtension(); - - if (!ext.compareIgnoreCase(".kwd")) - { - input = new KWIKFileSource(); - } - else - { - sendActionMessage("File type not supported"); - return false; - } - - if (!input->OpenFile(file)) - { - input = nullptr; - sendActionMessage("Invalid file"); - return false; - } - - if (input->getNumRecords() <= 0) - { - input = nullptr; - sendActionMessage("Empty file. Inoring open operation"); - return false; - } - static_cast<FileReaderEditor*>(getEditor())->populateRecordings(input); - setActiveRecording(0); + File file(fullpath); + + String ext = file.getFileExtension(); + + if (!ext.compareIgnoreCase(".kwd")) + { + input = new KWIKFileSource(); + } + else + { + sendActionMessage("File type not supported"); + return false; + } + + if (!input->OpenFile(file)) + { + input = nullptr; + sendActionMessage("Invalid file"); + return false; + } + + if (input->getNumRecords() <= 0) + { + input = nullptr; + sendActionMessage("Empty file. Inoring open operation"); + return false; + } + static_cast<FileReaderEditor*>(getEditor())->populateRecordings(input); + setActiveRecording(0); } void FileReader::setActiveRecording(int index) { - input->setActiveRecord(index); - currentNumChannels = input->getActiveNumChannels(); - currentNumSamples = input->getActiveNumSamples(); - currentSampleRate = input->getActiveSampleRate(); - startSample = 0; - stopSample = currentNumSamples; - currentSample = 0; - for (int i=0; i < currentNumChannels; i++) - { - channelInfo.add(input->getChannelInfo(i)); - } - static_cast<FileReaderEditor*>(getEditor())->setTotalTime(samplesToMilliseconds(currentNumSamples)); - readBuffer.malloc(currentNumChannels*BUFFER_SIZE); + input->setActiveRecord(index); + currentNumChannels = input->getActiveNumChannels(); + currentNumSamples = input->getActiveNumSamples(); + currentSampleRate = input->getActiveSampleRate(); + startSample = 0; + stopSample = currentNumSamples; + currentSample = 0; + for (int i=0; i < currentNumChannels; i++) + { + channelInfo.add(input->getChannelInfo(i)); + } + static_cast<FileReaderEditor*>(getEditor())->setTotalTime(samplesToMilliseconds(currentNumSamples)); + readBuffer.malloc(currentNumChannels*BUFFER_SIZE); } String FileReader::getFile() { if (input) - return input->getFileName(); - else - return String::empty; + return input->getFileName(); + else + return String::empty; } void FileReader::updateSettings() { - if (!input) return; + if (!input) return; - for (int i=0; i < currentNumChannels; i++) - { - channels[i]->bitVolts = channelInfo[i].bitVolts; - channels[i]->name = channelInfo[i].name; - } + for (int i=0; i < currentNumChannels; i++) + { + channels[i]->bitVolts = channelInfo[i].bitVolts; + channels[i]->name = channelInfo[i].name; + } } @@ -207,31 +207,31 @@ void FileReader::process(AudioSampleBuffer& buffer, MidiBuffer& events, int& nSa int samplesReaded = 0; - while (samplesReaded < samplesNeeded) - { - int samplesToRead = samplesNeeded - samplesReaded; - if ((currentSample + samplesToRead) > stopSample) - { - samplesToRead = stopSample - currentSample; - if (samplesToRead > 0) - input->readData(readBuffer+samplesReaded,samplesToRead); - input->seekTo(startSample); - currentSample = startSample; - } - else - { - input->readData(readBuffer+samplesReaded,samplesToRead); - currentSample += samplesToRead; - } - samplesReaded += samplesToRead; - } - for (int i=0; i < currentNumChannels; i++) - { - input->processChannelData(readBuffer,buffer.getWritePointer(i,0),i,samplesNeeded); - } - - timestamp += samplesNeeded; - static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); + while (samplesReaded < samplesNeeded) + { + int samplesToRead = samplesNeeded - samplesReaded; + if ((currentSample + samplesToRead) > stopSample) + { + samplesToRead = stopSample - currentSample; + if (samplesToRead > 0) + input->readData(readBuffer+samplesReaded,samplesToRead); + input->seekTo(startSample); + currentSample = startSample; + } + else + { + input->readData(readBuffer+samplesReaded,samplesToRead); + currentSample += samplesToRead; + } + samplesReaded += samplesToRead; + } + for (int i=0; i < currentNumChannels; i++) + { + input->processChannelData(readBuffer,buffer.getWritePointer(i,0),i,samplesNeeded); + } + + timestamp += samplesNeeded; + static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); nSamples = samplesNeeded; } @@ -239,30 +239,30 @@ void FileReader::process(AudioSampleBuffer& buffer, MidiBuffer& events, int& nSa void FileReader::setParameter(int parameterIndex, float newValue) { - switch (parameterIndex) - { - case 0: //Change selected recording - setActiveRecording(newValue); - break; - case 1: //set startTime - startSample = millisecondsToSamples(newValue); - currentSample = startSample; - static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); - break; - case 2: //set stop time - stopSample = millisecondsToSamples(newValue); - currentSample = startSample; - static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); - break; - } + switch (parameterIndex) + { + case 0: //Change selected recording + setActiveRecording(newValue); + break; + case 1: //set startTime + startSample = millisecondsToSamples(newValue); + currentSample = startSample; + static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); + break; + case 2: //set stop time + stopSample = millisecondsToSamples(newValue); + currentSample = startSample; + static_cast<FileReaderEditor*>(getEditor())->setCurrentTime(samplesToMilliseconds(currentSample)); + break; + } } unsigned int FileReader::samplesToMilliseconds(int64 samples) { - return (unsigned int)(1000.f*float(samples)/currentSampleRate); + return (unsigned int)(1000.f*float(samples)/currentSampleRate); } int64 FileReader::millisecondsToSamples(unsigned int ms) { - return (int64)(currentSampleRate*float(ms)/1000.f); + return (int64)(currentSampleRate*float(ms)/1000.f); } diff --git a/Source/Processors/FileReader/FileReader.h b/Source/Processors/FileReader/FileReader.h index e31286ac833786546adf7d994227ce55868db75e..ffd54c21206bd499009ad97ba9a7db668b5fc652 100644 --- a/Source/Processors/FileReader/FileReader.h +++ b/Source/Processors/FileReader/FileReader.h @@ -81,22 +81,22 @@ private: int64 timestamp; - float currentSampleRate; - int currentNumChannels; - int64 currentNumSamples; - int64 startSample; - int64 stopSample; - Array<RecordedChannelInfo> channelInfo; + float currentSampleRate; + int currentNumChannels; + int64 currentNumSamples; + int64 startSample; + int64 stopSample; + Array<RecordedChannelInfo> channelInfo; - int64 currentSample; + int64 currentSample; - ScopedPointer<FileSource> input; + ScopedPointer<FileSource> input; - HeapBlock<int16> readBuffer; + HeapBlock<int16> readBuffer; - void setActiveRecording(int index); - unsigned int samplesToMilliseconds(int64 samples); - int64 millisecondsToSamples(unsigned int ms); + void setActiveRecording(int index); + unsigned int samplesToMilliseconds(int64 samples); + int64 millisecondsToSamples(unsigned int ms); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FileReader); diff --git a/Source/Processors/FileReader/FileReaderEditor.cpp b/Source/Processors/FileReader/FileReaderEditor.cpp index 5ff34a3871ccc5dc059e8e408ce9fca20e5135b7..07111a940d75f990c9d7aa6edb293ef50427c15e 100644 --- a/Source/Processors/FileReader/FileReaderEditor.cpp +++ b/Source/Processors/FileReader/FileReaderEditor.cpp @@ -46,18 +46,18 @@ FileReaderEditor::FileReaderEditor(GenericProcessor* parentNode, bool useDefault fileNameLabel->setBounds(30,25,140,20); addAndMakeVisible(fileNameLabel); - recordSelector = new ComboBox("Recordings"); - recordSelector->setBounds(30,50,120,20); - recordSelector->addListener(this); - addAndMakeVisible(recordSelector); + recordSelector = new ComboBox("Recordings"); + recordSelector->setBounds(30,50,120,20); + recordSelector->addListener(this); + addAndMakeVisible(recordSelector); - currentTime = new DualTimeComponent(this, false); - currentTime->setBounds(5,80,175,20); - addAndMakeVisible(currentTime); + currentTime = new DualTimeComponent(this, false); + currentTime->setBounds(5,80,175,20); + addAndMakeVisible(currentTime); - timeLimits = new DualTimeComponent(this,true); - timeLimits->setBounds(5,105,175,20); - addAndMakeVisible(timeLimits); + timeLimits = new DualTimeComponent(this,true); + timeLimits->setBounds(5,105,175,20); + addAndMakeVisible(timeLimits); desiredWidth = 180; @@ -75,17 +75,17 @@ void FileReaderEditor::setFile(String file) File fileToRead(file); lastFilePath = fileToRead.getParentDirectory(); - if(fileReader->setFile(fileToRead.getFullPathName())) - { - fileNameLabel->setText(fileToRead.getFileName(), dontSendNotification); - - setEnabledState(true); - } - else - { - clearEditor(); - } - getEditorViewport()->makeEditorVisible(this, false, true); + if (fileReader->setFile(fileToRead.getFullPathName())) + { + fileNameLabel->setText(fileToRead.getFileName(), dontSendNotification); + + setEnabledState(true); + } + else + { + clearEditor(); + } + getEditorViewport()->makeEditorVisible(this, false, true); repaint(); } @@ -120,199 +120,198 @@ void FileReaderEditor::buttonEvent(Button* button) bool FileReaderEditor::setPlaybackStartTime(unsigned int ms) { - if (ms > timeLimits->getTimeMilliseconds(1)) - return false; - fileReader->setParameter(1,ms); - return true; + if (ms > timeLimits->getTimeMilliseconds(1)) + return false; + fileReader->setParameter(1,ms); + return true; } bool FileReaderEditor::setPlaybackStopTime(unsigned int ms) { - if ((ms > recTotalTime) || (ms < timeLimits->getTimeMilliseconds(0))) - return false; - fileReader->setParameter(2,ms); - return true; + if ((ms > recTotalTime) || (ms < timeLimits->getTimeMilliseconds(0))) + return false; + fileReader->setParameter(2,ms); + return true; } void FileReaderEditor::setTotalTime(unsigned int ms) { - timeLimits->setTimeMilliseconds(0,0); - timeLimits->setTimeMilliseconds(1,ms); - currentTime->setTimeMilliseconds(0,0); - currentTime->setTimeMilliseconds(1,ms); - recTotalTime = ms; + timeLimits->setTimeMilliseconds(0,0); + timeLimits->setTimeMilliseconds(1,ms); + currentTime->setTimeMilliseconds(0,0); + currentTime->setTimeMilliseconds(1,ms); + recTotalTime = ms; } void FileReaderEditor::setCurrentTime(unsigned int ms) { - MessageManagerLock mml; - currentTime->setTimeMilliseconds(0,ms); + MessageManagerLock mml; + currentTime->setTimeMilliseconds(0,ms); } -void FileReaderEditor::comboBoxChanged(ComboBox *combo) +void FileReaderEditor::comboBoxChanged(ComboBox* combo) { - fileReader->setParameter(0,combo->getSelectedId()-1); - getEditorViewport()->makeEditorVisible(this, false, true); + fileReader->setParameter(0,combo->getSelectedId()-1); + getEditorViewport()->makeEditorVisible(this, false, true); } void FileReaderEditor::populateRecordings(FileSource* source) { - recordSelector->clear(dontSendNotification); - for (int i=0; i < source->getNumRecords(); i++) - { - std::cout << "adding " << source->getRecordName(1) << std::endl; - recordSelector->addItem(source->getRecordName(i),i+1); - } - recordSelector->setSelectedId(1,dontSendNotification); + recordSelector->clear(dontSendNotification); + for (int i=0; i < source->getNumRecords(); i++) + { + recordSelector->addItem(source->getRecordName(i),i+1); + } + recordSelector->setSelectedId(1,dontSendNotification); } void FileReaderEditor::clearEditor() { - fileNameLabel->setText("No file selected.",dontSendNotification); - recordSelector->clear(dontSendNotification); - timeLimits->setTimeMilliseconds(0,0); - timeLimits->setTimeMilliseconds(1,0); - currentTime->setTimeMilliseconds(0,0); - currentTime->setTimeMilliseconds(1,0); - setEnabledState(false); + fileNameLabel->setText("No file selected.",dontSendNotification); + recordSelector->clear(dontSendNotification); + timeLimits->setTimeMilliseconds(0,0); + timeLimits->setTimeMilliseconds(1,0); + currentTime->setTimeMilliseconds(0,0); + currentTime->setTimeMilliseconds(1,0); + setEnabledState(false); } void FileReaderEditor::startAcquisition() { - recordSelector->setEnabled(false); - timeLimits->setEnable(false); - GenericEditor::startAcquisition(); + recordSelector->setEnabled(false); + timeLimits->setEnable(false); + GenericEditor::startAcquisition(); } void FileReaderEditor::stopAcquisition() { - recordSelector->setEnabled(true); - timeLimits->setEnable(true); - GenericEditor::stopAcquisition(); + recordSelector->setEnabled(true); + timeLimits->setEnable(true); + GenericEditor::stopAcquisition(); } void FileReaderEditor::saveCustomParameters(XmlElement* xml) { - xml->setAttribute("Type","FileReader"); - XmlElement* childNode = xml->createNewChildElement("FILENAME"); - childNode->setAttribute("path", fileReader->getFile()); - childNode->setAttribute("recording", recordSelector->getSelectedId()); - childNode = xml->createNewChildElement("TIME_LIMITS"); - childNode->setAttribute("start_time",(double)timeLimits->getTimeMilliseconds(0)); - childNode->setAttribute("stop_time",(double)timeLimits->getTimeMilliseconds(1)); + xml->setAttribute("Type","FileReader"); + XmlElement* childNode = xml->createNewChildElement("FILENAME"); + childNode->setAttribute("path", fileReader->getFile()); + childNode->setAttribute("recording", recordSelector->getSelectedId()); + childNode = xml->createNewChildElement("TIME_LIMITS"); + childNode->setAttribute("start_time",(double)timeLimits->getTimeMilliseconds(0)); + childNode->setAttribute("stop_time",(double)timeLimits->getTimeMilliseconds(1)); } void FileReaderEditor::loadCustomParameters(XmlElement* xml) { - forEachXmlChildElement(*xml, element) - { - if (element->hasTagName("FILENAME")) - { - String filepath = element->getStringAttribute("path"); - setFile(filepath); - int recording = element->getIntAttribute("recording"); - recordSelector->setSelectedId(recording,sendNotificationSync); - } - else if (element->hasTagName("TIME_LIMITS")) - { - unsigned int time; - time = (unsigned int)element->getDoubleAttribute("start_time"); - setPlaybackStartTime(time); - timeLimits->setTimeMilliseconds(0,time); - time = (unsigned int)element->getDoubleAttribute("stop_time"); - setPlaybackStopTime(time); - timeLimits->setTimeMilliseconds(1,time); - } - } + forEachXmlChildElement(*xml, element) + { + if (element->hasTagName("FILENAME")) + { + String filepath = element->getStringAttribute("path"); + setFile(filepath); + int recording = element->getIntAttribute("recording"); + recordSelector->setSelectedId(recording,sendNotificationSync); + } + else if (element->hasTagName("TIME_LIMITS")) + { + unsigned int time; + time = (unsigned int)element->getDoubleAttribute("start_time"); + setPlaybackStartTime(time); + timeLimits->setTimeMilliseconds(0,time); + time = (unsigned int)element->getDoubleAttribute("stop_time"); + setPlaybackStopTime(time); + timeLimits->setTimeMilliseconds(1,time); + } + } } -DualTimeComponent::DualTimeComponent(FileReaderEditor*e, bool isEditable) - : editor(e), editable(isEditable) +DualTimeComponent::DualTimeComponent(FileReaderEditor* e, bool isEditable) + : editor(e), editable(isEditable) { - Label* l; - l = new Label("Time1"); - l->setBounds(0,0,75,20); - l->setEditable(editable); - l->setFont(Font("Small Text",10,Font::plain)); - if (editable) - { - l->addListener(this); - l->setColour(Label::ColourIds::backgroundColourId,Colours::lightgrey); - l->setColour(Label::ColourIds::outlineColourId,Colours::black); - } - addAndMakeVisible(l); - timeLabel[0] = l; - - l = new Label("Time2"); - l->setBounds(85,0,75,20); - l->setEditable(editable); - l->setFont(Font("Small Text",10,Font::plain)); - if (editable) - { - l->addListener(this); - l->setColour(Label::ColourIds::backgroundColourId,Colours::lightgrey); - l->setColour(Label::ColourIds::outlineColourId,Colours::black); - } - addAndMakeVisible(l); - timeLabel[1] = l; - - setTimeMilliseconds(0,0); - setTimeMilliseconds(1,0); + Label* l; + l = new Label("Time1"); + l->setBounds(0,0,75,20); + l->setEditable(editable); + l->setFont(Font("Small Text",10,Font::plain)); + if (editable) + { + l->addListener(this); + l->setColour(Label::ColourIds::backgroundColourId,Colours::lightgrey); + l->setColour(Label::ColourIds::outlineColourId,Colours::black); + } + addAndMakeVisible(l); + timeLabel[0] = l; + + l = new Label("Time2"); + l->setBounds(85,0,75,20); + l->setEditable(editable); + l->setFont(Font("Small Text",10,Font::plain)); + if (editable) + { + l->addListener(this); + l->setColour(Label::ColourIds::backgroundColourId,Colours::lightgrey); + l->setColour(Label::ColourIds::outlineColourId,Colours::black); + } + addAndMakeVisible(l); + timeLabel[1] = l; + + setTimeMilliseconds(0,0); + setTimeMilliseconds(1,0); } DualTimeComponent::~DualTimeComponent() { } -void DualTimeComponent::paint(Graphics &g) +void DualTimeComponent::paint(Graphics& g) { - String sep; - g.setFont(Font("Small Text",10,Font::plain)); - g.setColour(Colours::darkgrey); - if (editable) - { - sep = "-"; - } - else - { - sep = "/"; - } - g.drawText(sep,78,0,5,20,Justification::centred,false); + String sep; + g.setFont(Font("Small Text",10,Font::plain)); + g.setColour(Colours::darkgrey); + if (editable) + { + sep = "-"; + } + else + { + sep = "/"; + } + g.drawText(sep,78,0,5,20,Justification::centred,false); } void DualTimeComponent::setTimeMilliseconds(unsigned int index, unsigned int time) { - int msFrac,secFrac,minFrac,hourFrac; - if (index > 1) return; + int msFrac,secFrac,minFrac,hourFrac; + if (index > 1) return; - msTime[index]=time; + msTime[index]=time; - msFrac = time%1000; - time /= 1000; - secFrac = time%60; - time /= 60; - minFrac = time%60; - time /= 60; - hourFrac = time; + msFrac = time%1000; + time /= 1000; + secFrac = time%60; + time /= 60; + minFrac = time%60; + time /= 60; + hourFrac = time; - String text = String(hourFrac).paddedLeft('0',2) + ":" + String(minFrac).paddedLeft('0',2) + ":" + - String(secFrac).paddedLeft('0',2) + "." + String(msFrac).paddedLeft('0',3); + String text = String(hourFrac).paddedLeft('0',2) + ":" + String(minFrac).paddedLeft('0',2) + ":" + + String(secFrac).paddedLeft('0',2) + "." + String(msFrac).paddedLeft('0',3); - timeLabel[index]->setText(text,dontSendNotification); + timeLabel[index]->setText(text,dontSendNotification); } unsigned int DualTimeComponent::getTimeMilliseconds(unsigned int index) { - if (index > 1) return 0; - return msTime[index]; + if (index > 1) return 0; + return msTime[index]; } void DualTimeComponent::setEnable(bool enable) { - timeLabel[0]->setEnabled(enable); - timeLabel[1]->setEnabled(enable); + timeLabel[0]->setEnabled(enable); + timeLabel[1]->setEnabled(enable); } void DualTimeComponent::labelTextChanged(Label* label) diff --git a/Source/Processors/FileReader/FileReaderEditor.h b/Source/Processors/FileReader/FileReaderEditor.h index 0797034c3652b6020578ef8db48a31640a47ffda..a94106a380b5001a291dcaf974da5a3502231de5 100644 --- a/Source/Processors/FileReader/FileReaderEditor.h +++ b/Source/Processors/FileReader/FileReaderEditor.h @@ -41,7 +41,7 @@ class FileSource; */ class FileReaderEditor : public GenericEditor, - public ComboBox::Listener + public ComboBox::Listener { public: @@ -56,53 +56,53 @@ public: void loadCustomParameters(XmlElement*); - bool setPlaybackStartTime(unsigned int ms); - bool setPlaybackStopTime(unsigned int ms); - void setTotalTime(unsigned int ms); - void setCurrentTime(unsigned int ms); + bool setPlaybackStartTime(unsigned int ms); + bool setPlaybackStopTime(unsigned int ms); + void setTotalTime(unsigned int ms); + void setCurrentTime(unsigned int ms); - void comboBoxChanged(ComboBox *combo); - void populateRecordings(FileSource* source); + void comboBoxChanged(ComboBox* combo); + void populateRecordings(FileSource* source); - void startAcquisition(); - void stopAcquisition(); + void startAcquisition(); + void stopAcquisition(); private: ScopedPointer<UtilityButton> fileButton; ScopedPointer<Label> fileNameLabel; - ScopedPointer<ComboBox> recordSelector; - ScopedPointer<DualTimeComponent> currentTime; - ScopedPointer<DualTimeComponent> timeLimits; + ScopedPointer<ComboBox> recordSelector; + ScopedPointer<DualTimeComponent> currentTime; + ScopedPointer<DualTimeComponent> timeLimits; FileReader* fileReader; - unsigned int recTotalTime; + unsigned int recTotalTime; File lastFilePath; - void clearEditor(); + void clearEditor(); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FileReaderEditor); }; class DualTimeComponent : public Component, - public Label::Listener + public Label::Listener { public: - DualTimeComponent(FileReaderEditor* e, bool isEditable); - ~DualTimeComponent(); - void setTimeMilliseconds(unsigned int index, unsigned int time); - unsigned int getTimeMilliseconds(unsigned int index); - void paint(Graphics& g); - void labelTextChanged(Label* label); - void setEnable(bool enable); + DualTimeComponent(FileReaderEditor* e, bool isEditable); + ~DualTimeComponent(); + void setTimeMilliseconds(unsigned int index, unsigned int time); + unsigned int getTimeMilliseconds(unsigned int index); + void paint(Graphics& g); + void labelTextChanged(Label* label); + void setEnable(bool enable); private: - ScopedPointer<Label> timeLabel[2]; - unsigned int msTime[2]; - FileReaderEditor* editor; - bool editable; + ScopedPointer<Label> timeLabel[2]; + unsigned int msTime[2]; + FileReaderEditor* editor; + bool editable; }; diff --git a/Source/Processors/FileReader/FileSource.cpp b/Source/Processors/FileReader/FileSource.cpp index a30b3ddabb1a51ac6c8eb1ac186703bf3c23d935..ab32ecbd392750d785a21dc83ec005d1b5191a1a 100644 --- a/Source/Processors/FileReader/FileSource.cpp +++ b/Source/Processors/FileReader/FileSource.cpp @@ -33,88 +33,88 @@ FileSource::~FileSource() int FileSource::getNumRecords() { - return numRecords; + return numRecords; } String FileSource::getRecordName(int index) { - return infoArray[index].name; + return infoArray[index].name; } int FileSource::getRecordNumChannels(int index) { - return infoArray[index].channels.size(); + return infoArray[index].channels.size(); } int FileSource::getActiveNumChannels() { - return getRecordNumChannels(activeRecord); + return getRecordNumChannels(activeRecord); } float FileSource::getRecordSampleRate(int index) { - return infoArray[index].sampleRate; + return infoArray[index].sampleRate; } float FileSource::getActiveSampleRate() { - return getRecordSampleRate(activeRecord); + return getRecordSampleRate(activeRecord); } int64 FileSource::getRecordNumSamples(int index) { - return infoArray[index].numSamples; + return infoArray[index].numSamples; } int64 FileSource::getActiveNumSamples() { - return getRecordNumSamples(activeRecord); + return getRecordNumSamples(activeRecord); } int FileSource::getActiveRecord() { - return activeRecord; + return activeRecord; } RecordedChannelInfo FileSource::getChannelInfo(int recordIndex, int channel) { - return infoArray[recordIndex].channels[channel]; + return infoArray[recordIndex].channels[channel]; } RecordedChannelInfo FileSource::getChannelInfo(int channel) { - return getChannelInfo(activeRecord, channel); + return getChannelInfo(activeRecord, channel); } void FileSource::setActiveRecord(int index) { - activeRecord = index; - updateActiveRecord(); + activeRecord = index; + updateActiveRecord(); } bool FileSource::fileIsOpened() { - return fileOpened; + return fileOpened; } String FileSource::getFileName() { - return filename; + return filename; } bool FileSource::OpenFile(File file) { - if (Open(file)) - { - fileOpened = true; - fillRecordInfo(); - filename = file.getFullPathName(); - } - else - { - fileOpened = false; - filename = String::empty; - } - return fileOpened; + if (Open(file)) + { + fileOpened = true; + fillRecordInfo(); + filename = file.getFullPathName(); + } + else + { + fileOpened = false; + filename = String::empty; + } + return fileOpened; } \ No newline at end of file diff --git a/Source/Processors/FileReader/FileSource.h b/Source/Processors/FileReader/FileSource.h index 2d2388c533f4ad2bf5a0acd161f6b72b44877a95..75f320d88076899c31ef1794399d9bb2ddc91b90 100644 --- a/Source/Processors/FileReader/FileSource.h +++ b/Source/Processors/FileReader/FileSource.h @@ -28,8 +28,8 @@ struct RecordedChannelInfo { - String name; - float bitVolts; + String name; + float bitVolts; }; class FileSource @@ -52,22 +52,22 @@ public: int getActiveNumChannels(); int64 getActiveNumSamples(); - RecordedChannelInfo getChannelInfo(int recordIndex, int channel); - RecordedChannelInfo getChannelInfo(int channel); + RecordedChannelInfo getChannelInfo(int recordIndex, int channel); + RecordedChannelInfo getChannelInfo(int channel); bool OpenFile(File file); bool fileIsOpened(); - String getFileName(); + String getFileName(); virtual int readData(int16* buffer, int nSamples) =0; - virtual void processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples)=0; + virtual void processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples)=0; virtual void seekTo(int64 sample) =0; protected: struct RecordInfo { String name; - Array<RecordedChannelInfo> channels; + Array<RecordedChannelInfo> channels; int64 numSamples; float sampleRate; }; @@ -76,7 +76,7 @@ protected: bool fileOpened; int numRecords; int activeRecord; - String filename; + String filename; private: virtual bool Open(File file)=0; diff --git a/Source/Processors/FileReader/KwikFileSource.cpp b/Source/Processors/FileReader/KwikFileSource.cpp index 3249b5487dde474c59f9e11f8c9271d72d079a51..d609d382f2f8c54c555ff8de33cbffeb8a0f199b 100644 --- a/Source/Processors/FileReader/KwikFileSource.cpp +++ b/Source/Processors/FileReader/KwikFileSource.cpp @@ -39,192 +39,194 @@ KWIKFileSource::~KWIKFileSource() bool KWIKFileSource::Open(File file) { - ScopedPointer<H5File> tmpFile; - Attribute ver; - uint16 vernum; - try - { - tmpFile = new H5File(file.getFullPathName().toUTF8(),H5F_ACC_RDONLY); - if (!tmpFile->attrExists("kwik_version")) - { - return false; - } - - ver = tmpFile->openAttribute("kwik_version"); - ver.read(PredType::NATIVE_UINT16,&vernum); - if ((vernum < MIN_KWIK_VERSION) || (vernum > MAX_KWIK_VERSION)) - { - return false; - } - - sourceFile = tmpFile; - return true; - - } - catch (FileIException error) - { - PROCESS_ERROR; - return false; - } - catch (AttributeIException error) - { - PROCESS_ERROR; - return false; - } - - //Code should never reach here - return false; + ScopedPointer<H5File> tmpFile; + Attribute ver; + uint16 vernum; + try + { + tmpFile = new H5File(file.getFullPathName().toUTF8(),H5F_ACC_RDONLY); + if (!tmpFile->attrExists("kwik_version")) + { + return false; + } + + ver = tmpFile->openAttribute("kwik_version"); + ver.read(PredType::NATIVE_UINT16,&vernum); + if ((vernum < MIN_KWIK_VERSION) || (vernum > MAX_KWIK_VERSION)) + { + return false; + } + + sourceFile = tmpFile; + return true; + + } + catch (FileIException error) + { + PROCESS_ERROR; + return false; + } + catch (AttributeIException error) + { + PROCESS_ERROR; + return false; + } + + //Code should never reach here + return false; } void KWIKFileSource::fillRecordInfo() { - Group recordings; - - try - { - recordings = sourceFile->openGroup("/recordings"); - int numObjs = recordings.getNumObjs(); - - for (int i=0; i < numObjs; i++) - { - try { - Group recordN; - DataSet data; - Attribute attr; - DataSpace dSpace; - float sampleRate; - hsize_t dims[3]; - RecordInfo info; - - recordN = recordings.openGroup(String(i).toUTF8()); - data = recordN.openDataSet("data"); - attr = recordN.openAttribute("sample_rate"); - attr.read(PredType::NATIVE_FLOAT,&sampleRate); - dSpace = data.getSpace(); - dSpace.getSimpleExtentDims(dims); - - info.name="Record "+String(i); - info.numSamples = dims[0]; - info.sampleRate = sampleRate; - - recordN = recordings.openGroup((String(i) + "/application_data").toUTF8()); - attr=recordN.openAttribute("channel_bit_volts"); - HeapBlock<float> bitVoltArray(dims[1]); - attr.read(ArrayType(PredType::NATIVE_FLOAT,1,&dims[1]),bitVoltArray); - - for (int i=0; i < dims[1]; i++) - { - RecordedChannelInfo c; - c.name = "CH" + i; - c.bitVolts = bitVoltArray[i]; - info.channels.add(c); - } - infoArray.add(info); - availableDataSets.add(i); - numRecords++; - } - catch (GroupIException) - { - } - catch(DataSetIException) - { - } - catch (AttributeIException) - { - } - catch (DataSpaceIException error) - { - PROCESS_ERROR; - } - } - } - catch(FileIException error) - { - PROCESS_ERROR; - } - catch(GroupIException error) - { - PROCESS_ERROR; - } + Group recordings; + + try + { + recordings = sourceFile->openGroup("/recordings"); + int numObjs = recordings.getNumObjs(); + + for (int i=0; i < numObjs; i++) + { + try + { + Group recordN; + DataSet data; + Attribute attr; + DataSpace dSpace; + float sampleRate; + hsize_t dims[3]; + RecordInfo info; + + recordN = recordings.openGroup(String(i).toUTF8()); + data = recordN.openDataSet("data"); + attr = recordN.openAttribute("sample_rate"); + attr.read(PredType::NATIVE_FLOAT,&sampleRate); + dSpace = data.getSpace(); + dSpace.getSimpleExtentDims(dims); + + info.name="Record "+String(i); + info.numSamples = dims[0]; + info.sampleRate = sampleRate; + + recordN = recordings.openGroup((String(i) + "/application_data").toUTF8()); + attr=recordN.openAttribute("channel_bit_volts"); + HeapBlock<float> bitVoltArray(dims[1]); + attr.read(ArrayType(PredType::NATIVE_FLOAT,1,&dims[1]),bitVoltArray); + + for (int i=0; i < dims[1]; i++) + { + RecordedChannelInfo c; + c.name = "CH" + i; + c.bitVolts = bitVoltArray[i]; + info.channels.add(c); + } + infoArray.add(info); + availableDataSets.add(i); + numRecords++; + } + catch (GroupIException) + { + } + catch (DataSetIException) + { + } + catch (AttributeIException) + { + } + catch (DataSpaceIException error) + { + PROCESS_ERROR; + } + } + } + catch (FileIException error) + { + PROCESS_ERROR; + } + catch (GroupIException error) + { + PROCESS_ERROR; + } } void KWIKFileSource::updateActiveRecord() { - samplePos=0; - try - { - String path = "/recordings/" + String(availableDataSets[activeRecord]) + "/data"; - dataSet = new DataSet(sourceFile->openDataSet(path.toUTF8())); - } - catch(FileIException error) - { - PROCESS_ERROR; - } - catch (DataSetIException error) - { - PROCESS_ERROR; - } + samplePos=0; + try + { + String path = "/recordings/" + String(availableDataSets[activeRecord]) + "/data"; + dataSet = new DataSet(sourceFile->openDataSet(path.toUTF8())); + } + catch (FileIException error) + { + PROCESS_ERROR; + } + catch (DataSetIException error) + { + PROCESS_ERROR; + } } void KWIKFileSource::seekTo(int64 sample) { - samplePos = sample % getActiveNumSamples(); + samplePos = sample % getActiveNumSamples(); } int KWIKFileSource::readData(int16* buffer, int nSamples) { - DataSpace fSpace,mSpace; - int samplesToRead; - int nChannels = getActiveNumChannels(); - hsize_t dim[3],offset[3]; - - if (samplePos + nSamples > getActiveNumSamples()) - { - samplesToRead = getActiveNumSamples() - samplePos; - } - else - { - samplesToRead = nSamples; - } - - try { - fSpace = dataSet->getSpace(); - dim[0] = samplesToRead; - dim[1] = nChannels; - dim[2] = 1; - offset[0] = samplePos; - offset[1] = 0; - offset[2] = 0; - - fSpace.selectHyperslab(H5S_SELECT_SET,dim,offset); - mSpace = DataSpace(2,dim); - - dataSet->read(buffer,PredType::NATIVE_INT16,mSpace,fSpace); - samplePos += samplesToRead; - return samplesToRead; - - } - catch (DataSetIException error) - { - PROCESS_ERROR; - return 0; - } - catch (DataSpaceIException error) - { - PROCESS_ERROR; - return 0; - } - return 0; + DataSpace fSpace,mSpace; + int samplesToRead; + int nChannels = getActiveNumChannels(); + hsize_t dim[3],offset[3]; + + if (samplePos + nSamples > getActiveNumSamples()) + { + samplesToRead = getActiveNumSamples() - samplePos; + } + else + { + samplesToRead = nSamples; + } + + try + { + fSpace = dataSet->getSpace(); + dim[0] = samplesToRead; + dim[1] = nChannels; + dim[2] = 1; + offset[0] = samplePos; + offset[1] = 0; + offset[2] = 0; + + fSpace.selectHyperslab(H5S_SELECT_SET,dim,offset); + mSpace = DataSpace(2,dim); + + dataSet->read(buffer,PredType::NATIVE_INT16,mSpace,fSpace); + samplePos += samplesToRead; + return samplesToRead; + + } + catch (DataSetIException error) + { + PROCESS_ERROR; + return 0; + } + catch (DataSpaceIException error) + { + PROCESS_ERROR; + return 0; + } + return 0; } void KWIKFileSource::processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples) { - int n = getActiveNumChannels(); - float bitVolts = getChannelInfo(channel).bitVolts; + int n = getActiveNumChannels(); + float bitVolts = getChannelInfo(channel).bitVolts; - for(int i=0; i < numSamples; i++) - { - *(outBuffer+i) = *(inBuffer+(n*i)+channel) * bitVolts; - } + for (int i=0; i < numSamples; i++) + { + *(outBuffer+i) = *(inBuffer+(n*i)+channel) * bitVolts; + } } \ No newline at end of file diff --git a/Source/Processors/FileReader/KwikFileSource.h b/Source/Processors/FileReader/KwikFileSource.h index 49af9d4b1b288954ee9d3f0390b8e16d33a449a9..b70d98e377549b9dd4577c3ddc6b08de822c7706 100644 --- a/Source/Processors/FileReader/KwikFileSource.h +++ b/Source/Processors/FileReader/KwikFileSource.h @@ -41,23 +41,23 @@ class DataType; class KWIKFileSource : public FileSource { public: - KWIKFileSource(); - ~KWIKFileSource(); - - int readData(int16* buffer, int nSamples); + KWIKFileSource(); + ~KWIKFileSource(); - void seekTo(int64 sample); + int readData(int16* buffer, int nSamples); - void processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples); + void seekTo(int64 sample); + + void processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples); private: - ScopedPointer<H5::H5File> sourceFile; - ScopedPointer<H5::DataSet> dataSet; - bool Open(File file); - void fillRecordInfo(); - void updateActiveRecord(); - int64 samplePos; - Array<int> availableDataSets; + ScopedPointer<H5::H5File> sourceFile; + ScopedPointer<H5::DataSet> dataSet; + bool Open(File file); + void fillRecordInfo(); + void updateActiveRecord(); + int64 samplePos; + Array<int> availableDataSets; };