diff --git a/examples/GetAllStreams.cpp b/examples/GetAllStreams.cpp index e2df8ec87..591331914 100644 --- a/examples/GetAllStreams.cpp +++ b/examples/GetAllStreams.cpp @@ -10,7 +10,7 @@ * resolved and displayed. This is useful for browsing applications. */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { try { std::cout << "Here is a one-shot resolve of all current streams:" << std::endl; @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) { std::this_thread::sleep_for(std::chrono::seconds(1)); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/GetFullinfo.cpp b/examples/GetFullinfo.cpp index c1596761b..9c15f4e8a 100644 --- a/examples/GetFullinfo.cpp +++ b/examples/GetFullinfo.cpp @@ -7,15 +7,15 @@ * resolve functions only includes the core information otherwise. */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { std::string field, value; if (argc != 3) { std::cout << "This connects to a stream which has a particular value for a given field and " - "displays its full stream_info contentss." - << std::endl; + "displays its full stream_info contentss." + << std::endl; std::cout << "Please enter a field name and the desired value (e.g. \"type EEG\" (without " - "the quotes)):" - << std::endl; + "the quotes)):" + << std::endl; std::cin >> field >> value; } else { field = argv[1]; @@ -36,11 +36,11 @@ int main(int argc, char* argv[]) { // get & display the info std::cout << "The information about this stream is displayed in the following: " - << std::endl; + << std::endl; lsl::stream_info info = inlet.info(); std::cout << info.as_xml() << std::endl; - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/GetTimeCorrection.cpp b/examples/GetTimeCorrection.cpp index d52daf219..ae829b4eb 100644 --- a/examples/GetTimeCorrection.cpp +++ b/examples/GetTimeCorrection.cpp @@ -9,15 +9,15 @@ * should be approx. 0 (up to some tolerance). */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { std::string field, value; if (argc != 3) { std::cout << "This connects to a stream which has a particular value for a given field and " - "gets the time-synchronization information for it." - << std::endl; + "gets the time-synchronization information for it." + << std::endl; std::cout << "Please enter a field name and the desired value (e.g. \"type EEG\" (without " - "the quotes)):" - << std::endl; + "the quotes)):" + << std::endl; std::cin >> field >> value; } else { field = argv[1]; @@ -38,13 +38,13 @@ int main(int argc, char* argv[]) { // start receiving & displaying the data std::cout << "Press [Enter] to query a new correction value (clocks may drift)..." - << std::endl; + << std::endl; while (true) { std::cout << inlet.time_correction() << std::endl; std::cin.get(); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/HandleMetaData.cpp b/examples/HandleMetaData.cpp index af5b3c1c6..dffe43d7f 100644 --- a/examples/HandleMetaData.cpp +++ b/examples/HandleMetaData.cpp @@ -1,24 +1,24 @@ #include #include -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { try { // create a new stream_info and declare some meta-data (in accordance with XDF format) - const char* name = argc > 1 ? argv[1] : "MetaTester"; + const char *name = argc > 1 ? argv[1] : "MetaTester"; lsl::stream_info info(name, "EEG", 8, 100, lsl::cf_float32, "myuid323457"); lsl::xml_element chns = info.desc().append_child("channels"); - const char* labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"}; - for (const char* label : labels) + const char *labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"}; + for (const char *label : labels) chns.append_child("channel") - .append_child_value("label", label) - .append_child_value("unit", "microvolts") - .append_child_value("type", "EEG"); + .append_child_value("label", label) + .append_child_value("unit", "microvolts") + .append_child_value("type", "EEG"); info.desc().append_child_value("manufacturer", "SCCN"); info.desc() - .append_child("cap") - .append_child_value("name", "EasyCap") - .append_child_value("size", "54") - .append_child_value("labelscheme", "10-20"); + .append_child("cap") + .append_child_value("name", "EasyCap") + .append_child_value("size", "54") + .append_child_value("labelscheme", "10-20"); // create outlet for the stream lsl::stream_outlet outlet(info); @@ -32,17 +32,17 @@ int main(int argc, char* argv[]) { // get the full stream info (including custom meta-data) and dissect it lsl::stream_info inf = inlet.info(); std::cout << "The stream's XML meta-data is: \n" - << inf.as_xml() - << "\nThe manufacturer is: " << inf.desc().child_value("manufacturer") - << "\nThe cap circumference is: " << inf.desc().child("cap").child_value("size") - << "\nThe channel labels are as follows:\n"; + << inf.as_xml() + << "\nThe manufacturer is: " << inf.desc().child_value("manufacturer") + << "\nThe cap circumference is: " << inf.desc().child("cap").child_value("size") + << "\nThe channel labels are as follows:\n"; lsl::xml_element ch = inf.desc().child("channels").child("channel"); for (int k = 0; k < info.channel_count(); k++) { std::cout << " " << ch.child_value("label") << std::endl; ch = ch.next_sibling(); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/HandleMetaDataC.c b/examples/HandleMetaDataC.c index 0cd1e8f5d..3a5b72189 100644 --- a/examples/HandleMetaDataC.c +++ b/examples/HandleMetaDataC.c @@ -1,51 +1,52 @@ #include #include -int main(int argc, char* argv[]) { - int c; /* channel index */ - lsl_xml_ptr desc,chns,chn,cap; /* some xml element pointers */ - lsl_outlet outlet; /* stream outlet */ - lsl_streaminfo info,inf; /* streaminfo objects */ - lsl_inlet inlet; /* a stream inlet to get samples from */ - int errcode; /* error code (lsl_lost_error or timeouts) */ - const char* labels[] = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"}; +int main(int argc, char *argv[]) { + int c; /* channel index */ + lsl_xml_ptr desc, chns, chn, cap; /* some xml element pointers */ + lsl_outlet outlet; /* stream outlet */ + lsl_streaminfo info, inf; /* streaminfo objects */ + lsl_inlet inlet; /* a stream inlet to get samples from */ + int errcode; /* error code (lsl_lost_error or timeouts) */ + const char *labels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"}; /* create a new streaminfo and declare some meta-data (in accordance with XDF format) */ - const char* name = argc > 1 ? argv[1] : "MetaTester"; - info = lsl_create_streaminfo(name,"EEG",8,100,cft_float32,"myuid323457"); + const char *name = argc > 1 ? argv[1] : "MetaTester"; + info = lsl_create_streaminfo(name, "EEG", 8, 100, cft_float32, "myuid323457"); desc = lsl_get_desc(info); - chns = lsl_append_child(desc,"channels"); - for (c=0;c<8;c++) { - chn = lsl_append_child(chns,"channel"); - lsl_append_child_value(chn,"label",labels[c]); - lsl_append_child_value(chn,"unit","microvolts"); - lsl_append_child_value(chn,"type","EEG"); + chns = lsl_append_child(desc, "channels"); + for (c = 0; c < 8; c++) { + chn = lsl_append_child(chns, "channel"); + lsl_append_child_value(chn, "label", labels[c]); + lsl_append_child_value(chn, "unit", "microvolts"); + lsl_append_child_value(chn, "type", "EEG"); } - lsl_append_child_value(desc,"manufacturer","SCCN"); - cap = lsl_append_child(desc,"cap"); - lsl_append_child_value(cap,"name","EasyCap"); - lsl_append_child_value(cap,"size","54"); - lsl_append_child_value(cap,"labelscheme","10-20"); + lsl_append_child_value(desc, "manufacturer", "SCCN"); + cap = lsl_append_child(desc, "cap"); + lsl_append_child_value(cap, "name", "EasyCap"); + lsl_append_child_value(cap, "size", "54"); + lsl_append_child_value(cap, "labelscheme", "10-20"); /* create outlet for the stream */ - outlet = lsl_create_outlet(info,0,360); + outlet = lsl_create_outlet(info, 0, 360); /* === the following could run on another computer === */ /* resolve the stream and open an inlet */ - lsl_resolve_byprop(&info,1,"name","MetaTester",1,LSL_FOREVER); + lsl_resolve_byprop(&info, 1, "name", "MetaTester", 1, LSL_FOREVER); inlet = lsl_create_inlet(info, 360, LSL_NO_PREFERENCE, 1); - inf = lsl_get_fullinfo(inlet,LSL_FOREVER,&errcode); + inf = lsl_get_fullinfo(inlet, LSL_FOREVER, &errcode); printf("The stream's XML meta-data is: \n"); - printf("%s\n",lsl_get_xml(inf)); - printf("The manufacturer is: %s\n",lsl_child_value_n(lsl_get_desc(inf),"manufacturer")); - printf("The cap circumference is: %s\n",lsl_child_value_n(lsl_child(lsl_get_desc(inf),"cap"),"size")); + printf("%s\n", lsl_get_xml(inf)); + printf("The manufacturer is: %s\n", lsl_child_value_n(lsl_get_desc(inf), "manufacturer")); + printf("The cap circumference is: %s\n", + lsl_child_value_n(lsl_child(lsl_get_desc(inf), "cap"), "size")); printf("The channel labels are as follows:\n"); - chn = lsl_child(lsl_child(lsl_get_desc(inf),"channels"),"channel"); - for (c=0; c #include #include #include +#include /** @@ -9,27 +9,25 @@ * network and how to connect to it in order to receive data. */ -void printChunk(const std::vector& chunk, std::size_t n_channels) { - for(std::size_t i=0; i < chunk.size(); ++i) { +void printChunk(const std::vector &chunk, std::size_t n_channels) { + for (std::size_t i = 0; i < chunk.size(); ++i) { std::cout << chunk[i] << ' '; - if (i % n_channels == n_channels - 1) - std::cout << '\n'; + if (i % n_channels == n_channels - 1) std::cout << '\n'; } } -void printChunk(const std::vector>& chunk) { - for(const auto& vec: chunk) - printChunk(vec, vec.size()); +void printChunk(const std::vector> &chunk) { + for (const auto &vec : chunk) printChunk(vec, vec.size()); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { std::string field, value; const int max_samples = argc > 3 ? std::stoi(argv[3]) : 10; if (argc < 3) { std::cout << "This connects to a stream which has a particular value for a " - "given field and receives data.\nPlease enter a field name and the desired " - "value (e.g. \"type EEG\" (without the quotes)):" - << std::endl; + "given field and receives data.\nPlease enter a field name and the desired " + "value (e.g. \"type EEG\" (without the quotes)):" + << std::endl; std::cin >> field >> value; } else { field = argv[1]; @@ -39,7 +37,7 @@ int main(int argc, char* argv[]) { // resolve the stream of interet std::cout << "Now resolving streams..." << std::endl; std::vector results = lsl::resolve_stream(field, value); - if(results.empty()) throw std::runtime_error("No stream found"); + if (results.empty()) throw std::runtime_error("No stream found"); std::cout << "Here is what was resolved: " << std::endl; std::cout << results[0].as_xml() << std::endl; @@ -54,7 +52,7 @@ int main(int argc, char* argv[]) { std::vector sample; std::vector> chunk_nested_vector; - for(int i=0; i < max_samples; ++i) { + for (int i = 0; i < max_samples; ++i) { // pull a single sample inlet.pull_sample(sample); printChunk(sample, inlet.get_channel_count()); @@ -73,7 +71,7 @@ int main(int argc, char* argv[]) { printChunk(sample, inlet.get_channel_count()); } - if(argc == 1) { + if (argc == 1) { std::cout << "Press any key to exit. " << std::endl; std::cin.get(); } diff --git a/examples/ReceiveDataC.c b/examples/ReceiveDataC.c index 38057d225..d1dc84f8b 100644 --- a/examples/ReceiveDataC.c +++ b/examples/ReceiveDataC.c @@ -2,38 +2,41 @@ #include /** -* Example program that demonstrates how to resolve a specific stream on the lab network and how to connect to it in order to receive data. -*/ + * Example program that demonstrates how to resolve a specific stream on the lab network and how to + * connect to it in order to receive data. + */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { - unsigned k,t; /* channel index */ - lsl_streaminfo info; /* the streaminfo returned by the resolve call */ - lsl_inlet inlet; /* a stream inlet to get samples from */ - int errcode; /* error code (lsl_lost_error or timeouts) */ - float cursample[8]; /* array to hold our current sample */ - double timestamp; /* time stamp of the current sample (in sender time) */ + unsigned k, t; /* channel index */ + lsl_streaminfo info; /* the streaminfo returned by the resolve call */ + lsl_inlet inlet; /* a stream inlet to get samples from */ + int errcode; /* error code (lsl_lost_error or timeouts) */ + float cursample[8]; /* array to hold our current sample */ + double timestamp; /* time stamp of the current sample (in sender time) */ - /* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be EEG, resolve at least 1 stream, wait forever if necessary) */ + /* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be + * EEG, resolve at least 1 stream, wait forever if necessary) */ printf("Now waiting for an EEG stream...\n"); - lsl_resolve_byprop(&info, 1, "type","EEG", 1, LSL_FOREVER); + lsl_resolve_byprop(&info, 1, "type", "EEG", 1, LSL_FOREVER); - /* make an inlet to read data from the stream (buffer max. 300 seconds of data, no preference regarding chunking, automatic recovery enabled) */ + /* make an inlet to read data from the stream (buffer max. 300 seconds of data, no preference + * regarding chunking, automatic recovery enabled) */ inlet = lsl_create_inlet(info, 300, LSL_NO_PREFERENCE, 1); - /* subscribe to the stream (automatically done by push, but a nice way of checking early on that we can connect successfully) */ - lsl_open_stream(inlet,LSL_FOREVER,&errcode); - if (errcode != 0) - return errcode; + /* subscribe to the stream (automatically done by push, but a nice way of checking early on that + * we can connect successfully) */ + lsl_open_stream(inlet, LSL_FOREVER, &errcode); + if (errcode != 0) return errcode; printf("Displaying data...\n"); - for(t=0;t<100000000;t++) { - /* get the next sample form the inlet (read into cursample, 8 values, wait forever if necessary) and return the timestamp if we got something */ - timestamp = lsl_pull_sample_f(inlet,cursample,8,LSL_FOREVER,&errcode); + for (t = 0; t < 100000000; t++) { + /* get the next sample form the inlet (read into cursample, 8 values, wait forever if + * necessary) and return the timestamp if we got something */ + timestamp = lsl_pull_sample_f(inlet, cursample, 8, LSL_FOREVER, &errcode); /* print the data */ - for (k=0; k<8; ++k) - printf("\t%.2f", cursample[k]); + for (k = 0; k < 8; ++k) printf("\t%.2f", cursample[k]); printf("\n"); } diff --git a/examples/ReceiveDataInChunks.cpp b/examples/ReceiveDataInChunks.cpp index 941dfdba6..5ff2fd678 100644 --- a/examples/ReceiveDataInChunks.cpp +++ b/examples/ReceiveDataInChunks.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include // define a packed sample struct (here a stereo sample). @@ -9,7 +9,7 @@ struct stereo_sample { int16_t l, r; }; -int main(int, char* []) { +int main(int, char *[]) { try { // resolve the stream of interest & make an inlet @@ -23,7 +23,7 @@ int main(int, char* []) { std::cout << timestamp << std::endl; // only showing the time stamps here } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/ReceiveDataSimple.cpp b/examples/ReceiveDataSimple.cpp index 1f69a0e07..47c21f4d6 100644 --- a/examples/ReceiveDataSimple.cpp +++ b/examples/ReceiveDataSimple.cpp @@ -2,11 +2,12 @@ #include /** - * This is a minimal example that demonstrates how a multi-channel stream (here 128ch) of a particular name (here: SimpleStream) can be - * resolved into an inlet, and how the raw sample data & time stamps are pulled from the inlet. This example does not display the obtained data. + * This is a minimal example that demonstrates how a multi-channel stream (here 128ch) of a + * particular name (here: SimpleStream) can be resolved into an inlet, and how the raw sample data & + * time stamps are pulled from the inlet. This example does not display the obtained data. */ -int main(int argc, char** argv) { +int main(int argc, char **argv) { using namespace lsl; // resolve the stream of interest & make an inlet to get data from the first result diff --git a/examples/ReceiveStringMarkers.cpp b/examples/ReceiveStringMarkers.cpp index 6f3e78d56..c36ed5866 100644 --- a/examples/ReceiveStringMarkers.cpp +++ b/examples/ReceiveStringMarkers.cpp @@ -9,14 +9,14 @@ * pulled from their source */ -int main(int, char**) { +int main(int, char **) { // resolve the stream of interet std::vector> inlets; - for (auto& stream_info : lsl::resolve_stream("type", "Markers")) { + for (auto &stream_info : lsl::resolve_stream("type", "Markers")) { if (stream_info.channel_count() != 1) std::cerr << "Skipping stream " << stream_info.name() - << " because it has more than one channel" << std::endl; + << " because it has more than one channel" << std::endl; else { inlets.emplace_back(new lsl::stream_inlet(stream_info)); std::cout << "Listening to " << stream_info.name() << std::endl; @@ -30,10 +30,10 @@ int main(int, char**) { std::string sample; double starttime = lsl::local_clock(); while (true) { - for (auto& inlet : inlets) + for (auto &inlet : inlets) if (double ts = inlet->pull_sample(&sample, 1, .2)) std::cout << (ts - inlet->time_correction(1) - starttime) << '\t' << sample - << std::endl; + << std::endl; } return 0; } diff --git a/examples/ReceiveStringMarkersC.c b/examples/ReceiveStringMarkersC.c index 682e77599..44882903c 100644 --- a/examples/ReceiveStringMarkersC.c +++ b/examples/ReceiveStringMarkersC.c @@ -2,30 +2,32 @@ #include /** -* Example program that demonstrates how to resolve a specific stream on the lab network and how -* to connect to it in order to receive string-formatted markers. -*/ + * Example program that demonstrates how to resolve a specific stream on the lab network and how + * to connect to it in order to receive string-formatted markers. + */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { - lsl_streaminfo info; /* the streaminfo returned by the resolve call */ - lsl_inlet inlet; /* a stream inlet to get samples from */ - int errcode; /* error code (lsl_lost_error or timeouts) */ - char *cursample; /* array to hold our current sample */ - double timestamp; /* time stamp of the current sample (in sender time) */ + lsl_streaminfo info; /* the streaminfo returned by the resolve call */ + lsl_inlet inlet; /* a stream inlet to get samples from */ + int errcode; /* error code (lsl_lost_error or timeouts) */ + char *cursample; /* array to hold our current sample */ + double timestamp; /* time stamp of the current sample (in sender time) */ - /* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be EEG, resolve at least 1 stream, wait forever if necessary) */ + /* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be + * EEG, resolve at least 1 stream, wait forever if necessary) */ printf("Now waiting for a Markers stream...\n"); - lsl_resolve_byprop(&info,1, "type","Markers", 1, LSL_FOREVER); + lsl_resolve_byprop(&info, 1, "type", "Markers", 1, LSL_FOREVER); - /* make an inlet to read data from the stream (buffer max. 300k markers, no preference regarding chunking, automatic recovery enabled) */ + /* make an inlet to read data from the stream (buffer max. 300k markers, no preference regarding + * chunking, automatic recovery enabled) */ inlet = lsl_create_inlet(info, 300, LSL_NO_PREFERENCE, 1); /* start receiving & displaying the data */ printf("Displaying data...\n"); while (1) { - timestamp = lsl_pull_sample_str(inlet,&cursample,1,LSL_FOREVER,&errcode); - printf("got: %s at time %.3f\n",cursample,timestamp); + timestamp = lsl_pull_sample_str(inlet, &cursample, 1, LSL_FOREVER, &errcode); + printf("got: %s at time %.3f\n", cursample, timestamp); } /* we never get here, but anyway */ diff --git a/examples/SendData.cpp b/examples/SendData.cpp index c5c0ee7db..744fd981a 100644 --- a/examples/SendData.cpp +++ b/examples/SendData.cpp @@ -1,24 +1,29 @@ #include "lsl_cpp.h" #include -#include #include +#include using namespace std; /** -* This example program offers an 8-channel stream, float-formatted, that resembles EEG data. -* The example demonstrates also how per-channel meta-data can be specified using the .desc() field of the stream information object. -* -* Note that the timer used in the send loop of this program is not particularly accurate. -*/ + * This example program offers an 8-channel stream, float-formatted, that resembles EEG data. + * The example demonstrates also how per-channel meta-data can be specified using the .desc() field + * of the stream information object. + * + * Note that the timer used in the send loop of this program is not particularly accurate. + */ -const char *channels[] = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"}; +const char *channels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"}; -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { string name, type; if (argc != 3) { - cout << "This opens a stream under some user-defined name and with a user-defined content type." << endl; - cout << "Please enter the stream name and the stream type (e.g. \"BioSemi EEG\" (without the quotes)):" << endl; + cout << "This opens a stream under some user-defined name and with a user-defined content " + "type." + << endl; + cout << "Please enter the stream name and the stream type (e.g. \"BioSemi EEG\" (without " + "the quotes)):" + << endl; cin >> name >> type; } else { name = argv[1]; @@ -28,38 +33,37 @@ int main(int argc, char* argv[]) { try { // make a new stream_info (100 Hz) - lsl::stream_info info(name,type,8,100,lsl::cf_float32,string(name)+=type); + lsl::stream_info info(name, type, 8, 100, lsl::cf_float32, string(name) += type); // add some description fields info.desc().append_child_value("manufacturer", "BioSemi"); lsl::xml_element chns = info.desc().append_child("channels"); - for (int k=0;k<8;k++) + for (int k = 0; k < 8; k++) chns.append_child("channel") - .append_child_value("label",channels[k]) - .append_child_value("unit","microvolts") - .append_child_value("type","EEG"); + .append_child_value("label", channels[k]) + .append_child_value("unit", "microvolts") + .append_child_value("type", "EEG"); // make a new outlet lsl::stream_outlet outlet(info); // send data forever cout << "Now sending data... " << endl; - double starttime = ((double)clock())/CLOCKS_PER_SEC; - for(unsigned t=0;;t++) { - + double starttime = ((double)clock()) / CLOCKS_PER_SEC; + for (unsigned t = 0;; t++) { + // wait a bit and create random data - while (((double)clock())/CLOCKS_PER_SEC < starttime + t*0.01); + while (((double)clock()) / CLOCKS_PER_SEC < starttime + t * 0.01) + ; float sample[8]; - for (int c=0;c<8;c++) - sample[c] = (float)((rand()%1500)/500.0-1.5); + for (int c = 0; c < 8; c++) sample[c] = (float)((rand() % 1500) / 500.0 - 1.5); // send the sample outlet.push_sample(sample); } - } catch(std::exception &e) { - cerr << "Got an exception: " << e.what() << endl; - } - cout << "Press any key to exit. " << endl; cin.get(); + } catch (std::exception &e) { cerr << "Got an exception: " << e.what() << endl; } + cout << "Press any key to exit. " << endl; + cin.get(); return 0; } diff --git a/examples/SendDataC.c b/examples/SendDataC.c index 132ae01bb..e5484516a 100644 --- a/examples/SendDataC.c +++ b/examples/SendDataC.c @@ -4,49 +4,51 @@ /** * This example program offers an 8-channel stream, float-formatted, that resembles EEG data. - * The example demonstrates also how per-channel meta-data can be specified using the description field of the streaminfo object. + * The example demonstrates also how per-channel meta-data can be specified using the description + * field of the streaminfo object. * * Note that the app sends data as fast as it can - * Generally, you should sleep between sending samples and send multiple samples at once (push_chunk_*-functions) + * Generally, you should sleep between sending samples and send multiple samples at once + * (push_chunk_*-functions) */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { printf("SendDataC example program. Sends 8 float channels as fast as possible.\n"); printf("Usage: %s [streamname] [streamuid]\n", argv[0]); printf("Using lsl %d, lsl_library_info: %s\n", lsl_library_version(), lsl_library_info()); - const char* name = argc > 1 ? argv[1] : "SendDataC"; - const char* uid = argc > 2 ? argv[2] : "325wqer4354"; - /* declare a new streaminfo (name: SendDataC / argument 1, content type: EEG, 8 channels, 500 Hz, float values, some made-up device id (can also be empty) */ + const char *name = argc > 1 ? argv[1] : "SendDataC"; + const char *uid = argc > 2 ? argv[2] : "325wqer4354"; + /* declare a new streaminfo (name: SendDataC / argument 1, content type: EEG, 8 channels, 500 + * Hz, float values, some made-up device id (can also be empty) */ lsl_streaminfo info = lsl_create_streaminfo(name, "EEG", 8, 500, cft_float32, uid); /* add some meta-data fields to it */ /* (for more standard fields, see https://github.com/sccn/xdf/wiki/Meta-Data) */ lsl_xml_ptr desc = lsl_get_desc(info); lsl_append_child_value(desc, "manufacturer", "LSL"); - const char *channels[] = {"C3","C4","Cz","FPz","POz","CPz","O1","O2"}; - lsl_xml_ptr chns = lsl_append_child(desc,"channels"); - for (int c=0;c<8;c++) { - lsl_xml_ptr chn = lsl_append_child(chns,"channel"); - lsl_append_child_value(chn,"label",channels[c]); - lsl_append_child_value(chn,"unit","microvolts"); - lsl_append_child_value(chn,"type","EEG"); + const char *channels[] = {"C3", "C4", "Cz", "FPz", "POz", "CPz", "O1", "O2"}; + lsl_xml_ptr chns = lsl_append_child(desc, "channels"); + for (int c = 0; c < 8; c++) { + lsl_xml_ptr chn = lsl_append_child(chns, "channel"); + lsl_append_child_value(chn, "label", channels[c]); + lsl_append_child_value(chn, "unit", "microvolts"); + lsl_append_child_value(chn, "type", "EEG"); } /* make a new outlet (chunking: default, buffering: 360 seconds) */ - lsl_outlet outlet = lsl_create_outlet(info,0,360); + lsl_outlet outlet = lsl_create_outlet(info, 0, 360); do printf("Waiting for consumers\n"); - while(!lsl_wait_for_consumers(outlet, 120)); - + while (!lsl_wait_for_consumers(outlet, 120)); + printf("Now sending data...\n"); - + /* send data until the last consumer has disconnected */ - for(int t=0;lsl_have_consumers(outlet);t++) { + for (int t = 0; lsl_have_consumers(outlet); t++) { float cursample[8]; /* the current sample */ - cursample[0] = (float) t; - for (int c=1;c<8;c++) - cursample[c] = (float)((rand()%1500)/500.0-1.5); - lsl_push_sample_f(outlet,cursample); + cursample[0] = (float)t; + for (int c = 1; c < 8; c++) cursample[c] = (float)((rand() % 1500) / 500.0 - 1.5); + lsl_push_sample_f(outlet, cursample); } printf("Lost the last consumer, shutting down\n"); lsl_destroy_outlet(outlet); diff --git a/examples/SendDataInChunks.cpp b/examples/SendDataInChunks.cpp index 3aafa4d00..2ffce9a4b 100644 --- a/examples/SendDataInChunks.cpp +++ b/examples/SendDataInChunks.cpp @@ -37,7 +37,7 @@ int main(int argc, char **argv) { outlet.push_chunk_numeric_structs(mychunk); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/SendDataSimple.cpp b/examples/SendDataSimple.cpp index d1f58411b..90c30aab3 100644 --- a/examples/SendDataSimple.cpp +++ b/examples/SendDataSimple.cpp @@ -1,6 +1,6 @@ -#include // std::this_thread::sleep_for -#include // std::chrono::seconds +#include // std::chrono::seconds #include +#include // std::this_thread::sleep_for /** * This is an example of how a simple data stream can be offered on the network. @@ -10,18 +10,19 @@ const int nchannels = 8; -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { // make a new stream_info (nchannelsch) and open an outlet with it lsl::stream_info info(argc > 1 ? argv[1] : "SimpleStream", "EEG", nchannels); lsl::stream_outlet outlet(info); - while(!outlet.wait_for_consumers(120)); + while (!outlet.wait_for_consumers(120)) + ; // send data forever float sample[nchannels]; - while(outlet.have_consumers()) { + while (outlet.have_consumers()) { // generate random data - for (int c=0;c 1 ? argv[1] : "MultiStream"; + const char *name = argc > 1 ? argv[1] : "MultiStream"; const int rate = argc > 2 ? std::stoi(argv[2]) : 1000; std::vector outlets; - for(auto fmt: {lsl::cf_int16, lsl::cf_int32, lsl::cf_int64, lsl::cf_double64, lsl::cf_string}) - outlets.emplace_back(lsl::stream_info(name + std::to_string(fmt), "Example", 1, rate, fmt), 0, 360); + for (auto fmt : + {lsl::cf_int16, lsl::cf_int32, lsl::cf_int64, lsl::cf_double64, lsl::cf_string}) + outlets.emplace_back( + lsl::stream_info(name + std::to_string(fmt), "Example", 1, rate, fmt), 0, 360); std::cout << "Now sending data..." << std::endl; std::vector mychunk(rate); @@ -19,18 +21,16 @@ int main(int argc, char** argv) { auto nextsample = Clock::now(); for (int c = 0; c < rate * 600;) { // increment the sample counter - for (auto& sample : mychunk) - sample = c++; + for (auto &sample : mychunk) sample = c++; nextsample += std::chrono::seconds(1); std::this_thread::sleep_until(nextsample); double ts = lsl::local_clock(); - for(auto& outlet: outlets) - outlet.push_chunk_multiplexed(mychunk, ts); + for (auto &outlet : outlets) outlet.push_chunk_multiplexed(mychunk, ts); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/SendStringMarkers.cpp b/examples/SendStringMarkers.cpp index 6020bcbf7..3c7a9b83c 100644 --- a/examples/SendStringMarkers.cpp +++ b/examples/SendStringMarkers.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include /** @@ -10,9 +10,9 @@ * The name of the stream can be chosen as a startup parameter. */ -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { try { - const char* name = argc > 1 ? argv[1] : "MyEventStream"; + const char *name = argc > 1 ? argv[1] : "MyEventStream"; // make a new stream_info lsl::stream_info info(name, "Markers", 1, lsl::IRREGULAR_RATE, lsl::cf_string, "id23443"); @@ -21,12 +21,13 @@ int main(int argc, char* argv[]) { // send random marker strings std::cout << "Now sending markers... " << std::endl; - std::vector markertypes{"Test", "Blah", "Marker", "XXX", "Testtest", "Test-1-2-3"}; + std::vector markertypes{ + "Test", "Blah", "Marker", "XXX", "Testtest", "Test-1-2-3"}; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution rnd(0, markertypes.size() - 1); std::uniform_int_distribution delayrnd(0, 1000); - while(true) { + while (true) { // wait for a 20ms std::this_thread::sleep_for(std::chrono::milliseconds(delayrnd(gen))); // and choose the marker to send @@ -36,7 +37,7 @@ int main(int argc, char* argv[]) { // now send it (note the &) outlet.push_sample(&mrk); } - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } std::cout << "Press any key to exit. " << std::endl; std::cin.get(); return 0; diff --git a/examples/SendStringMarkersC.c b/examples/SendStringMarkersC.c index 876fb629b..d3177b834 100644 --- a/examples/SendStringMarkersC.c +++ b/examples/SendStringMarkersC.c @@ -7,41 +7,43 @@ void sleep_(int ms) { Sleep(ms); } #else #include -void sleep_(int ms) { usleep(ms*1000); } +void sleep_(int ms) { usleep(ms * 1000); } #endif /** -* This example program offers a 1-channel stream which contains strings. -* The stream has the "Marker" content type and irregular rate. + * This example program offers a 1-channel stream which contains strings. + * The stream has the "Marker" content type and irregular rate. */ -int main(int argc, char* argv[]) { - lsl_streaminfo info; /* out stream declaration object */ - lsl_outlet outlet; /* stream outlet */ - double endtime; /* used for send timing */ - const char *mrk; /* marker to send next */ +int main(int argc, char *argv[]) { + lsl_streaminfo info; /* out stream declaration object */ + lsl_outlet outlet; /* stream outlet */ + double endtime; /* used for send timing */ + const char *mrk; /* marker to send next */ - /* declare a new streaminfo (name: "MyEventStream", content type: "Markers", 1 channel, irregular rate, ... */ + /* declare a new streaminfo (name: "MyEventStream", content type: "Markers", 1 channel, + * irregular rate, ... */ /* ... string values, some made-up source id (can also be empty) */ - const char* name = argc > 1 ? argv[1] : "MyEventStream"; + const char *name = argc > 1 ? argv[1] : "MyEventStream"; info = lsl_create_streaminfo(name, "Markers", 1, LSL_IRREGULAR_RATE, cft_string, "id23443"); /* make a new outlet (chunking: default, buffering: 360k markers) */ - outlet = lsl_create_outlet(info,0,360); + outlet = lsl_create_outlet(info, 0, 360); - /* send random marker streams (note: this loop is keeping the CPU busy, normally one would sleep or yield here) */ + /* send random marker streams (note: this loop is keeping the CPU busy, normally one would sleep + * or yield here) */ printf("Now sending markers...\n"); const char *markertypes[] = {"Test", "Blah", "Marker", "XXX", "Testtest", "Test-1-2-3"}; - while(1) { + while (1) { /* wait for a random period of time */ - sleep_(rand()%1000); + sleep_(rand() % 1000); /* and choose the marker to send */ - mrk = markertypes[rand() % (sizeof(markertypes)/sizeof(markertypes[0]))]; - printf("now sending: %s\n",mrk); + mrk = markertypes[rand() % (sizeof(markertypes) / sizeof(markertypes[0]))]; + printf("now sending: %s\n", mrk); /* now send it (note the &, since this function takes an array of char*) */ - lsl_push_sample_str(outlet,&mrk); + lsl_push_sample_str(outlet, &mrk); } /* we never get here, buy anyway */ diff --git a/examples/TestSyncWithoutData.cpp b/examples/TestSyncWithoutData.cpp index 1a2a85dbc..b6a5ac424 100644 --- a/examples/TestSyncWithoutData.cpp +++ b/examples/TestSyncWithoutData.cpp @@ -1,9 +1,9 @@ -#include +#include // std::chrono::seconds #include -#include // std::chrono::seconds -#include // std::this_thread::sleep_for +#include +#include // std::this_thread::sleep_for -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { try { lsl::stream_info info("SyncTest", "Test", 1, lsl::IRREGULAR_RATE, lsl::cf_int16, "id23443"); @@ -17,26 +17,26 @@ int main(int argc, char* argv[]) { lsl::stream_inlet inlet(si); - //inlet.open_stream(2); - //outlet.wait_for_consumers(2); + // inlet.open_stream(2); + // outlet.wait_for_consumers(2); - std::thread push_thread{[&](){ - std::this_thread::sleep_for(std::chrono::seconds(10)); - std::cout << "Pushing data now" << std::endl; - for(int16_t i=0; i<10; ++i) { - outlet.push_sample(&i); - std::this_thread::sleep_for(std::chrono::seconds(1)); - } + std::thread push_thread{[&]() { + std::this_thread::sleep_for(std::chrono::seconds(10)); + std::cout << "Pushing data now" << std::endl; + for (int16_t i = 0; i < 10; ++i) { + outlet.push_sample(&i); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } }}; - for(auto end = lsl::local_clock() + 20; lsl::local_clock() < end;) { + for (auto end = lsl::local_clock() + 20; lsl::local_clock() < end;) { try { std::cout << "Got time correction: " << inlet.time_correction(1) << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1)); - } catch(std::exception& e) { + } catch (std::exception &e) { std::cout << "Error getting time correction data: " << e.what() << std::endl; } } push_thread.join(); - } catch (std::exception& e) { std::cerr << "Got an exception: " << e.what() << std::endl; } + } catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; } return 0; }