Ejemplo n.º 1
0
// Poll reports whether there is input available in the stream.
func (s *Stream) Poll() (bool, error) {
	poll := C.Pm_Poll(unsafe.Pointer(s.pmStream))
	if poll < 0 {
		return false, convertToError(C.PmError(poll))
	}
	return poll > 0, nil
}
Ejemplo n.º 2
0
// ReadSysExBytes reads 4*max sysex bytes from the input stream.
func (s *Stream) ReadSysExBytes(max int) ([]byte, error) {
	if max > maxEventBufferSize {
		return nil, ErrMaxBuffer
	}
	if max < minEventBufferSize {
		return nil, ErrMinBuffer
	}
	buffer := make([]C.PmEvent, max)
	numEvents := C.Pm_Read(unsafe.Pointer(s.pmStream), &buffer[0], C.int32_t(max))
	if numEvents < 0 {
		return nil, convertToError(C.PmError(numEvents))
	}
	msg := make([]byte, 4*numEvents)
	for i := 0; i < int(numEvents); i++ {
		msg[4*i+0] = byte(buffer[i].message & 0xFF)
		msg[4*i+1] = byte((buffer[i].message >> 8) & 0xFF)
		msg[4*i+2] = byte((buffer[i].message >> 16) & 0xFF)
		msg[4*i+3] = byte((buffer[i].message >> 24) & 0xFF)
	}
	return msg, nil
}
Ejemplo n.º 3
0
// Reads from the input stream, the max number events to be read are
// determined by max.
func (s *Stream) Read(max int) (events []Event, err error) {
	if max > maxEventBufferSize {
		return nil, ErrMaxBuffer
	}
	if max < minEventBufferSize {
		return nil, ErrMinBuffer
	}
	buffer := make([]C.PmEvent, max)
	numEvents := C.Pm_Read(unsafe.Pointer(s.pmStream), &buffer[0], C.int32_t(max))
	if numEvents < 0 {
		return nil, convertToError(C.PmError(numEvents))
	}
	events = make([]Event, numEvents)
	for i := 0; i < int(numEvents); i++ {
		events[i] = Event{
			Timestamp: Timestamp(buffer[i].timestamp),
			Status:    int64(buffer[i].message) & 0xFF,
			Data1:     (int64(buffer[i].message) >> 8) & 0xFF,
			Data2:     (int64(buffer[i].message) >> 16) & 0xFF,
		}
	}
	return
}