File: ReceiveStringMarkers.cpp

package info (click to toggle)
liblsl 1.16.2b1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,724 kB
  • sloc: cpp: 12,515; ansic: 666; python: 28; sh: 25; makefile: 18
file content (39 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <lsl_cpp.h>
#include <memory>
#include <string>

/**
 * This example program demonstrates how a Marker string stream on the network (here of any name)
 * can be resolved, and how the marker strings (assumed to be delivered at irregular rate) can be
 * pulled from their source
 */

int main(int, char **) {
	// resolve the stream of interet
	std::vector<std::unique_ptr<lsl::stream_inlet>> inlets;

	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;
		else {
			inlets.emplace_back(new lsl::stream_inlet(stream_info));
			std::cout << "Listening to " << stream_info.name() << std::endl;
		}
	}
	if (inlets.empty()) {
		std::cerr << "No marker stream found" << std::endl;
		return 0;
	}

	std::string sample;
	double starttime = lsl::local_clock();
	while (true) {
		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;
	}
	return 0;
}