addpath('/Users/roboos/matlab/liblsl-maca64');
addpath('/Users/roboos/matlab/liblsl-maca64/bin');

% instantiate the library
disp('Loading library...');
lib = lsl_loadlib();
disp(lsl_library_version(lib));

% make a new stream outlet
disp('Creating a new streaminfo...');
info = lsl_streaminfo(lib, 'BioSemi', 'EEG', 8, 100, 'cf_float32', 'my_laptop');

disp('Opening an outlet...');
outlet = lsl_outlet(info);

%%

% record data using LabRecorder
system('open /opt/homebrew/Cellar/labrecorder/1.16.2_9/LabRecorder/LabRecorder.app')

%%

% send markers into the outlet
disp('Now transmitting markers...');
markers = {'Test', 'Blah', 'Marker', 'XXX', 'Testtest', 'Test-1-2-3'};
while true
  pause(rand()*3);
  % pick a random marker
  mrk = markers{min(length(markers), 1+floor(rand()*(length(markers))))};
  disp(['now sending ' mrk]);
  outlet.push_sample({mrk});   % note that the string is wrapped into a cell-array
end

%%

% send data into the outlet, sample by sample
disp('Now transmitting data...');
while true
  outlet.push_sample(randn(8, 1));
  pause(0.01);
end

