Skip to content

Commit

Permalink
Move sample group selection dialog to correct location. Command line …
Browse files Browse the repository at this point in the history
…now expect sampling group as file argument.
  • Loading branch information
FlorianFranzen committed Nov 14, 2015
1 parent 4212d6e commit 17fb0ca
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
23 changes: 14 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,15 @@ int main(int argc, char *argv[])
SR = args.at(++i);
} else if (arg == "-t" || arg == "--timeWindow" || arg == "-timeWindow") {
timeWindow = args.at(++i);
} else {
handled = false;
}
} else {
#ifdef WITH_CEREBUS
if (arg == "-n" || arg == "--stream" || arg == "-stream") {
} else if (arg == "-n" || arg == "--stream" || arg == "-stream") {
streamMode = true;
} else {
#endif
} else {
handled = false;
#ifdef WITH_CEREBUS
}
#endif
} else {
handled = false;
}
// Nothing know. Treat it as path.
if (!handled)
Expand All @@ -128,7 +124,16 @@ int main(int argc, char *argv[])
neuroscope->show();
#ifdef WITH_CEREBUS
if (streamMode) {
neuroscope->openDocumentStream();
if(!file.isEmpty()) {
int group = file.toInt();
if(group > 0 && group < 6) {
neuroscope->openNetworkStream(static_cast<CerebusTracesProvider::SamplingGroup>(group));
} else {
std::cerr << "Sampling group must be between 1 (500 samp/sec) and 5 (30k samp/sec)." << std::endl;
}
} else {
std::cerr << "Network stream mode expects a sampling group as file argument." << std::endl;
}
} else {
#endif
if (!file.isEmpty()) {
Expand Down
31 changes: 27 additions & 4 deletions src/neuroscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void NeuroscopeApp::openDocumentFile(const QString& url)
}

#ifdef WITH_CEREBUS
void NeuroscopeApp::openDocumentStream()
void NeuroscopeApp::openNetworkStream(CerebusTracesProvider::SamplingGroup group)
{
slotStatusMsg(tr("Opening stream..."));

Expand All @@ -1084,7 +1084,7 @@ void NeuroscopeApp::openDocumentStream()
this->filePath = "cerebus.nsx";

// Open stream
if(!doc->openStream()) {
if(!doc->openStream(group)) {
QApplication::restoreOverrideCursor();
doc->closeDocument();
resetState();
Expand All @@ -1107,7 +1107,9 @@ void NeuroscopeApp::openDocumentStream()
QApplication::restoreOverrideCursor();
} else {
// ToDo: Check if we are already in streaming mode
if (!QProcess::startDetached("neuroscope", QStringList() << "-n")) {
if (!QProcess::startDetached("neuroscope", QStringList()
<< "-n"
<< QString::number(group))) {
QMessageBox::critical(this, tr("Neuroscope"),tr("neuroscope can not be launch"));
}
QApplication::restoreOverrideCursor();
Expand Down Expand Up @@ -1326,7 +1328,28 @@ void NeuroscopeApp::slotStreamOpen()
{
slotStatusMsg(tr("Opening network stream..."));

openDocumentStream();
// Let user choose sampling rate
QStringList items;
items << "30 000 Hz" << "10 000 Hz" << "2000 Hz" << "1000 Hz" << "500 Hz";

CerebusTracesProvider::SamplingGroup mapping[5] = {
CerebusTracesProvider::RATE_30k,
CerebusTracesProvider::RATE_10k,
CerebusTracesProvider::RATE_2K,
CerebusTracesProvider::RATE_1K,
CerebusTracesProvider::RATE_500
};

bool ok;
int answer = items.indexOf(QInputDialog::getItem(0, tr("Network Stream"),
tr("Please choose the sampling group to be displayed."),
items,
0, // current
false, //editable
&ok));

if (ok && answer >= 0)
openNetworkStream(mapping[answer]);

slotStatusMsg(tr("Ready."));
}
Expand Down
7 changes: 6 additions & 1 deletion src/neuroscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
//application specific include files
#include "neuroscopeview.h"

#ifdef WITH_CEREBUS
#include "cerebustraceprovider.h" // For SamplingGroup
#endif


// forward declaration of the Neuroscope classes
class NeuroscopeDoc;
class PrefDialog;
Expand Down Expand Up @@ -72,7 +77,7 @@ class NeuroscopeApp : public QMainWindow
/** Open a stream, only one document (file or stream) at the time allowed.
* Asking for a new one will open a new instance of the application with it.
*/
void openDocumentStream();
void openNetworkStream(CerebusTracesProvider::SamplingGroup group);
#endif

/** Returns a pointer to the current document connected to the NeuroscopeApp instance and is used by
Expand Down
27 changes: 1 addition & 26 deletions src/neuroscopedoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,32 +581,7 @@ int NeuroscopeDoc::openDocument(const QString& url)
}

#ifdef WITH_CEREBUS
bool NeuroscopeDoc::openStream() {
// Let user choose sampling rate
QStringList items;
items << "30 000 Hz" << "10 000 Hz" << "2000 Hz" << "1000 Hz" << "500 Hz";

CerebusTracesProvider::SamplingGroup mapping[5] = {
CerebusTracesProvider::RATE_30k,
CerebusTracesProvider::RATE_10k,
CerebusTracesProvider::RATE_2K,
CerebusTracesProvider::RATE_1K,
CerebusTracesProvider::RATE_500
};

bool ok;
int answer = items.indexOf(QInputDialog::getItem(0, tr("Network Stream"),
tr("Please choose the sampling group to be displayed."),
items,
0, // current
false, //editable
&ok));

if (!ok || answer < 0)
return false;

CerebusTracesProvider::SamplingGroup group = mapping[answer];

bool NeuroscopeDoc::openStream(CerebusTracesProvider::SamplingGroup group) {
// Open network stream
CerebusTracesProvider* cerebusTracesProvider = new CerebusTracesProvider(group);

Expand Down
8 changes: 4 additions & 4 deletions src/neuroscopedoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

#include <QEvent>




//include files for the application
#include "channelpalette.h"
#include "dataprovider.h"
#include "eventsprovider.h"

#ifdef WITH_CEREBUS
#include "cerebustraceprovider.h" // For SamplingGroup
#endif

// forward declaration of the Neuroscope classes
class NeuroscopeView;
Expand Down Expand Up @@ -118,7 +118,7 @@ class NeuroscopeDoc : public QObject
/** Open network stream.
* @return true on sucess, false otherwise.
*/
bool openStream();
bool openStream(CerebusTracesProvider::SamplingGroup group);
#endif

/**Saves the current session: displays, spike, cluster, event files opened and selected clusters and events.
Expand Down

0 comments on commit 17fb0ca

Please sign in to comment.