Skip to content
Snippets Groups Projects
Commit dd501b86 authored by jsiegle's avatar jsiegle
Browse files

File Reader can load and save paths

parent 0515cd13
Branches
Tags
No related merge requests found
......@@ -21,7 +21,7 @@
*/
#include "../SourceNode.h"
#include "FileReaderThread.h"
FileReaderThread::FileReaderThread(SourceNode* sn) :
......@@ -67,6 +67,15 @@ void FileReaderThread::setFile(String fullpath)
fseek(input, 0, SEEK_END);
lengthOfInputFile = ftell(input);
rewind(input);
sn->tryEnablingEditor();
}
String FileReaderThread::getFile()
{
return filePath;
}
bool FileReaderThread::foundInputSource()
......
......@@ -57,6 +57,7 @@ public:
float getBitVolts();
void setFile(String fullpath);
String getFile();
private:
int lengthOfInputFile;
......
......@@ -51,6 +51,15 @@ FileReaderEditor::~FileReaderEditor()
}
void FileReaderEditor::setFile(String file)
{
File fileToRead(file);
lastFilePath = fileToRead.getParentDirectory();
thread->setFile(fileToRead.getFullPathName());
fileNameLabel->setText(fileToRead.getFileName(),false);
}
void FileReaderEditor::buttonEvent(Button* button)
{
......@@ -67,13 +76,13 @@ void FileReaderEditor::buttonEvent(Button* button)
if (chooseFileReaderFile.browseForFileToOpen())
{
// Use the selected file
File fileToRead(chooseFileReaderFile.getResult());
setFile(chooseFileReaderFile.getResult().getFullPathName());
lastFilePath = fileToRead.getParentDirectory();
// lastFilePath = fileToRead.getParentDirectory();
thread->setFile(fileToRead.getFullPathName());
// thread->setFile(fileToRead.getFullPathName());
fileNameLabel->setText(fileToRead.getFileName(),false);
// fileNameLabel->setText(fileToRead.getFileName(),false);
}
}
......
......@@ -48,6 +48,8 @@ public:
void buttonEvent(Button* button);
void setFile(String file);
private:
ScopedPointer<UtilityButton> fileButton;
......
......@@ -532,7 +532,7 @@ void GenericProcessor::saveParametersToChannelsXml(juce::XmlElement* channelPare
selectionState->setAttribute("audio",a);
}
void GenericProcessor::saveToXml(juce::XmlElement* parentElement)
void GenericProcessor::saveToXml(XmlElement* parentElement)
{
std::cout <<"Creating channel xml elements" << std::endl;
......@@ -564,6 +564,13 @@ void GenericProcessor::saveToXml(juce::XmlElement* parentElement)
editorChildNode = parentElement->createNewChildElement("EDITOR");
getEditor()->saveEditorParameters(editorChildNode);
saveCustomParametersToXml(parentElement);
}
void GenericProcessor::saveCustomParametersToXml(XmlElement* parentElement)
{
}
void GenericProcessor::loadFromXml()
......@@ -594,6 +601,7 @@ void GenericProcessor::loadFromXml()
getEditor()->setChannelSelectionState(channelNum,
subNode->getBoolAttribute("param"),
subNode->getBoolAttribute("record"),
subNode->getBoolAttribute("audio"));
}
}
......@@ -604,6 +612,13 @@ void GenericProcessor::loadFromXml()
}
}
loadCustomParametersFromXml();
}
void GenericProcessor::loadCustomParametersFromXml()
{
}
......
......@@ -534,12 +534,18 @@ public:
/** Returns the parameter for a given index.*/
Parameter& getParameterReference(int parameterIndex);
/** Saving all settings to XML*/
/** Save generic settings to XML (called by all processors).*/
void saveToXml(XmlElement* parentElement);
/** Load settings from XML*/
/** Saving custom settings to XML. */
virtual void saveCustomParametersToXml(XmlElement* parentElement);
/** Load generic settings from XML (called by all processors). */
void loadFromXml();
/** Load custom settings from XML*/
virtual void loadCustomParametersFromXml();
/** Saving Parameters for each Channel */
void saveParametersToChannelsXml(XmlElement* channelParent, int channelNumber);
......
......@@ -47,33 +47,11 @@ SourceNode::SourceNode(const String& name_)
}
else if (getName().equalsIgnoreCase("Custom FPGA"))
{
dataThread = new FPGAThread(this);//FPGAThread(this);
dataThread = new FPGAThread(this);
}
else if (getName().equalsIgnoreCase("File Reader"))
{
// sendActionMessage("Select a file...");
// FileChooser chooseFileReaderFile("Please select the file you want to load...",
// File::getCurrentWorkingDirectory(),
// "*");
// if (chooseFileReaderFile.browseForFileToOpen())
// {
// // Use the selected file
// File fileToRead(chooseFileReaderFile.getResult());
// String fileName(fileToRead.getFullPathName());
// dataThread = new FileReaderThread(this, fileName.getCharPointer());
// }
// else
// {
// If cancelled, assume it's in the resources directory (only works on Linux)
dataThread = new FileReaderThread(this); //, "../../../Resources/DataFiles/data_stream_16ch_cortex");
// }
//sendActionMessage("File loaded.");
dataThread = new FileReaderThread(this);
}
else if (getName().equalsIgnoreCase("Rhythm FPGA"))
{
......@@ -408,3 +386,39 @@ void SourceNode::process(AudioSampleBuffer& buffer,
}
}
void SourceNode::saveCustomParametersToXml(XmlElement* parentElement)
{
if (getName().equalsIgnoreCase("File Reader"))
{
XmlElement* childNode = parentElement->createNewChildElement("FILENAME");
FileReaderThread* thread = (FileReaderThread*) dataThread.get();
childNode->setAttribute("path", thread->getFile());
}
}
void SourceNode::loadCustomParametersFromXml()
{
if (parametersAsXml != nullptr)
{
// use parametersAsXml to restore state
forEachXmlChildElement(*parametersAsXml, xmlNode)
{
if (xmlNode->hasTagName("FILENAME"))
{
String filepath = xmlNode->getStringAttribute("path");
FileReaderEditor* fre = (FileReaderEditor*) getEditor();
fre->setFile(filepath);
}
}
}
}
\ No newline at end of file
......@@ -85,6 +85,11 @@ public:
int getTTLState();
void saveCustomParametersToXml(XmlElement* parentElement);
void loadCustomParametersFromXml();
bool tryEnablingEditor();
private:
int numEventChannels;
......@@ -106,7 +111,7 @@ private:
int ttlState;
void updateSettings();
bool tryEnablingEditor();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SourceNode);
......
......@@ -1059,12 +1059,9 @@ XmlElement* EditorViewport::createNodeXml(GenericEditor* editor,
e->setAttribute("name", name);
e->setAttribute("insertionPoint", insertionPt);
/**Saves parameters to XML */
/**Saves individual processor parameters to XML */
std::cout << "Create subnodes with parameters" << std::endl;
source->saveToXml(e);
// source->stateSaved = true;
//GenericProcessor* dest = (GenericProcessor*) source->getDestNode();
return e;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment