Example #1
0
func main() {
	dev := flag.String("d", "/dev/input/by-id/usb-0810_Twin_USB_Joystick-event-joystick", "The GH controller event device")
	flag.Int64Var(&baseNote, "b", 48, "The base midi note with no button pressed")
	flag.Int64Var(&vel, "v", 100, "Midi note velocity")
	flag.Int64Var(&midiChan, "c", 1, "Midi channel")
	flag.Parse()
	portmidi.Initialize()
	out, err := portmidi.NewOutputStream(portmidi.GetDefaultOutputDeviceId(), 32, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	c := make(chan *evdev.InputEvent)
	e := make(chan error)
	go ReadGuitar(c, e, *dev)

	for {
		select {
		case but := <-c:
			switch but.Code {
			case butGreen, butRed, butYellow, butBlue, butOrange:
				SetNote(butMap[but.Code], but.Value)
				if playing != -1 {
					SwapNote(out, baseNote+butState+octave, vel)
				}
			case butStrumbar:
				if but.Value == 255 || but.Value == 0 {
					NoteOn(out, baseNote+butState+octave, vel)
				} else if !hold {
					NoteOff(out, playing, vel)
				}
			case butSelect:
				if but.Value != 0 {
					hold = !hold
					if !hold {
						NoteOff(out, playing, vel)
					}
				}
			case butTilt:
				if but.Value == 1 {
					octave += 12
				} else {
					octave -= 12
				}
				if playing != -1 {
					SwapNote(out, baseNote+butState+octave, vel)
				}
			case butStart:
				AllNotesOff(out)
			}
		case err := <-e:
			fmt.Println(err)
			close(c)
			close(e)
			return
		default:
		}
	}
}
Example #2
0
func ExampleWriteSysExBytes() {
	out, err := portmidi.NewOutputStream(portmidi.GetDefaultOutputDeviceId(), 1024, 0)
	if err != nil {
		log.Fatal(err)
	}

	if err = out.WriteSysExBytes(portmidi.Time(), []byte{0xF0, 0x0A, 0x0A, 0x1B, 0x00, 0x7F, 0x30, 0xF7}); err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func ExampleWriteSysEx() {
	out, err := portmidi.NewOutputStream(portmidi.GetDefaultOutputDeviceId(), 1024, 0)
	if err != nil {
		log.Fatal(err)
	}

	if err = out.WriteSysEx(portmidi.Time(), "F0 0A 0A 1B 00 7F 30 F7"); err != nil {
		log.Fatal(err)
	}
}
Example #4
0
func findMidiOutputDevice(name string) (portmidi.DeviceId, string) {
	devcount := portmidi.CountDevices()
	for i := 0; i < devcount; i++ {
		id := portmidi.DeviceId(i)
		info := portmidi.GetDeviceInfo(id)
		if info.IsOutputAvailable {
			if info.Name == name {
				return id, info.Name
			}
		}
	}
	id := portmidi.GetDefaultOutputDeviceId()
	info := portmidi.GetDeviceInfo(id)
	return id, info.Name
}