createInlet<T> static method

Future<LSLInlet<T>> createInlet<T>({
  1. required LSLStreamInfo streamInfo,
  2. int maxBuffer = 360,
  3. int chunkSize = 0,
  4. bool recover = true,
  5. double createTimeout = LSL_FOREVER,
  6. bool includeMetadata = false,
  7. bool useIsolates = true,
})

Creates a new inlet object.

streamInfo is the LSLStreamInfo object to be used. Probably obtained from a LSLStreamResolver. maxBuffer this is the either seconds (if streamInfo.sampleRate is specified) or 100s of samples (if not). chunkSize is the maximum number of samples. If 0, the default chunk length from the stream is used. recover is whether to recover from lost samples. createTimeout is the timeout for creating the inlet. includeMetadata if true, the stream info will include metadata access. This will automatically fetch full stream info with metadata. useIsolates determines whether to use isolates for thread safety. If true, the inlet will use isolates to ensure thread safety. Important: If you do not use isolates, you must ensure that you deal with the consequences of blocking operations which will block the main dart isolate.

Implementation

static Future<LSLInlet<T>> createInlet<T>({
  required LSLStreamInfo streamInfo,
  int maxBuffer = 360,
  int chunkSize = 0,
  bool recover = true,
  double createTimeout = LSL_FOREVER,
  bool includeMetadata = false,
  bool useIsolates = true,
}) async {
  if (!streamInfo.created) {
    throw LSLException('StreamInfo not created');
  }

  Type dataType;
  switch (streamInfo.channelFormat.dartType) {
    case const (double):
      dataType = double;
      break;
    case const (int):
      dataType = int;
      break;
    case const (String):
      dataType = String;
      break;
    default:
      throw LSLException('Invalid channel format');
  }

  // Check if the generic type matches the expected data type
  if (T != dynamic && T != dataType) {
    throw LSLException(
      'Generic type $T does not match expected data type $dataType for channel format ${streamInfo.channelFormat}',
    );
  }

  // Create inlet and get full info if metadata is requested
  LSLInlet inlet;
  if (dataType == double) {
    inlet = LSLInlet<double>(
      streamInfo,
      maxBuffer: maxBuffer,
      chunkSize: chunkSize,
      recover: recover,
      createTimeout: createTimeout,
      useIsolates: useIsolates,
    );
  } else if (dataType == int) {
    inlet = LSLInlet<int>(
      streamInfo,
      maxBuffer: maxBuffer,
      chunkSize: chunkSize,
      recover: recover,
      createTimeout: createTimeout,
      useIsolates: useIsolates,
    );
  } else if (dataType == String) {
    inlet = LSLInlet<String>(
      streamInfo,
      maxBuffer: maxBuffer,
      chunkSize: chunkSize,
      recover: recover,
      createTimeout: createTimeout,
      useIsolates: useIsolates,
    );
  } else {
    throw LSLException('Unsupported data type: $dataType');
  }

  await inlet.create();

  // If metadata is requested and we don't already have it, get full info from the inlet
  if (includeMetadata && streamInfo is! LSLStreamInfoWithMetadata) {
    await inlet.getFullInfo(timeout: createTimeout);
  }

  return inlet as LSLInlet<T>;
}