diff --git a/src/main.cpp b/src/main.cpp index 2d10415..204b10d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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) @@ -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(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()) { diff --git a/src/neuroscope.cpp b/src/neuroscope.cpp index 4057c55..5a9e0ab 100644 --- a/src/neuroscope.cpp +++ b/src/neuroscope.cpp @@ -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...")); @@ -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(); @@ -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(); @@ -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.")); } diff --git a/src/neuroscope.h b/src/neuroscope.h index 5aec409..0aac273 100644 --- a/src/neuroscope.h +++ b/src/neuroscope.h @@ -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; @@ -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 diff --git a/src/neuroscopedoc.cpp b/src/neuroscopedoc.cpp index bd1951e..e8defeb 100644 --- a/src/neuroscopedoc.cpp +++ b/src/neuroscopedoc.cpp @@ -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); diff --git a/src/neuroscopedoc.h b/src/neuroscopedoc.h index bbe99e6..bffaaaa 100644 --- a/src/neuroscopedoc.h +++ b/src/neuroscopedoc.h @@ -28,14 +28,14 @@ #include - - - //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; @@ -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.