Пример #1
0
func (s *SystemPort) Open() error {
	if s.isOpen && s.stream == nil {
		return errors.New("Underlying portmidi port is already opened, " +
			"but stream is not connected to this SystemPort.")
	}
	if s.id == -1 || s.isOpen { // Fake port or opened already, ignore.
		return nil
	}
	var errNum C.PmError
	if s.IsInputPort {
		// The input / output naming LOOKS backwards, but we're opening a
		// portmidi "output stream" for input Ports and vice versa.
		errNum = C.Pm_OpenOutput(&(s.stream), C.PmDeviceID(s.id),
			nil, C.int32_t(512), nil, nil, 0)
	} else {
		errNum = C.Pm_OpenInput(&(s.stream), C.PmDeviceID(s.id),
			nil, C.int32_t(512), nil, nil)
	}
	if errNum == 0 {
		s.isOpen = true
		s.stop = make(chan bool, 1)
		s.noteOns = make(chan Note, BufferSize)
		s.noteOffs = make(chan Note, BufferSize)
		s.controlChanges = make(chan ControlChange, BufferSize)
	}
	return makePortMidiError(errNum)
}
Пример #2
0
// Initializes a new input stream.
func NewInputStream(deviceId DeviceId, bufferSize int64) (stream *Stream, err error) {
	var str *C.PmStream
	errCode := C.Pm_OpenInput(
		(*unsafe.Pointer)(unsafe.Pointer(&str)),
		C.PmDeviceID(deviceId), nil, C.int32_t(bufferSize), nil, nil)
	if errCode != 0 {
		return nil, convertToError(errCode)
	}
	return &Stream{deviceId: deviceId, pmStream: str}, nil
}
Пример #3
0
// NewInputStream initializes a new input stream.
func NewInputStream(id DeviceID, bufferSize int64) (stream *Stream, err error) {
	var str *C.PmStream
	errCode := C.Pm_OpenInput(
		(*unsafe.Pointer)(unsafe.Pointer(&str)),
		C.PmDeviceID(id), nil, C.int32_t(bufferSize), nil, nil)
	if errCode != 0 {
		return nil, convertToError(errCode)
	}
	if info := Info(id); !info.IsInputAvailable {
		return nil, ErrInputUnavailable
	}
	return &Stream{deviceID: id, pmStream: str}, nil
}