场景音频支持midi键盘设备输入
This commit is contained in:
1 parent
de924984a8
commit
cc056b2d2c
5 files changed
+44
-42
No files matched your search
+22
-30
@@ -16,7 +16,6 @@ import (
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
"gitlab.com/gomidi/midi/v2"
|
||||
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
||||
"gitlab.com/gomidi/midi/v2/smf"
|
||||
)
|
||||
|
||||
@@ -26,31 +25,21 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
AUDIO_CHAN = make(chan uint32, 1000)
|
||||
MidiInputDevStopListenFunc func() = nil
|
||||
AudioChan = make(chan uint32, 1000)
|
||||
MidiInputDevStop func() = nil
|
||||
)
|
||||
|
||||
func sendMidiMsg(msg midi.Message) {
|
||||
if msg.Type() != midi.NoteOnMsg {
|
||||
return
|
||||
}
|
||||
var channel, key, velocity uint8
|
||||
msg.GetNoteOn(&channel, &key, &velocity)
|
||||
// TODO 测试一下客户端是否支持更宽的音域
|
||||
if !msg.GetNoteStart(&channel, &key, &velocity) {
|
||||
return
|
||||
}
|
||||
// 60 -> 中央C C4
|
||||
// if key < 36 || key > 71 {
|
||||
// continue
|
||||
// }
|
||||
note := int32(key) + int32(KeyOffset)
|
||||
if note < 21 || note > 108 {
|
||||
// 非88键钢琴音域
|
||||
if note < 36 || note > 96 {
|
||||
return
|
||||
}
|
||||
if velocity == 0 {
|
||||
// 可能是NoteOffMsg
|
||||
return
|
||||
}
|
||||
AUDIO_CHAN <- uint32(note)
|
||||
AudioChan <- uint32(note)
|
||||
}
|
||||
|
||||
func PlayAudio(fileData []byte) {
|
||||
@@ -69,17 +58,17 @@ func PlayAudio(fileData []byte) {
|
||||
metricTicks := audio.TimeFormat.(smf.MetricTicks)
|
||||
tickTime := ((60000000.0 / tempoChange.BPM) / float64(metricTicks.Resolution())) / 1000.0
|
||||
logger.Debug("start play audio")
|
||||
// 全部轨道
|
||||
for _, track := range audio.Tracks {
|
||||
// 全部轨道
|
||||
totalTick := uint64(0)
|
||||
for _, event := range track {
|
||||
// 单个轨道
|
||||
delay := uint32(float64(event.Delta) * tickTime)
|
||||
// busyPollWaitMilliSecond(delay)
|
||||
interruptWaitMilliSecond(delay)
|
||||
totalTick += uint64(delay)
|
||||
sendMidiMsg(midi.Message(event.Message))
|
||||
}
|
||||
// 单个轨道
|
||||
go func(track smf.Track) {
|
||||
for _, event := range track {
|
||||
delay := uint32(float64(event.Delta) * tickTime)
|
||||
// busyPollWaitMilliSecond(delay)
|
||||
interruptWaitMilliSecond(delay)
|
||||
sendMidiMsg(midi.Message(event.Message))
|
||||
}
|
||||
}(track)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +93,7 @@ func StartMidiInputDev() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
MidiInputDevStopListenFunc, err = midi.ListenTo(in, func(msg midi.Message, timestampms int32) {
|
||||
MidiInputDevStop, err = midi.ListenTo(in, func(msg midi.Message, timestampms int32) {
|
||||
logger.Debug("midi input dev msg: %v", msg)
|
||||
sendMidiMsg(msg)
|
||||
})
|
||||
@@ -115,7 +104,7 @@ func StartMidiInputDev() error {
|
||||
}
|
||||
|
||||
func StopMidiInputDev() {
|
||||
MidiInputDevStopListenFunc()
|
||||
MidiInputDevStop()
|
||||
midi.CloseDriver()
|
||||
}
|
||||
|
||||
@@ -124,6 +113,7 @@ const (
|
||||
SCREEN_HEIGHT = 80
|
||||
SCREEN_DPI = 0.5
|
||||
)
|
||||
|
||||
const GADGET_ID = 70590015
|
||||
|
||||
var SCREEN_ENTITY_ID_LIST []uint32
|
||||
@@ -139,6 +129,7 @@ const (
|
||||
GADGET_CYAN_BLUE = 70590018
|
||||
GADGET_PURPLE = 70590020
|
||||
)
|
||||
|
||||
const (
|
||||
RED_RGB = "C3764F"
|
||||
GREEN_RGB = "559F30"
|
||||
@@ -158,6 +149,7 @@ var COLOR_GADGET_MAP = map[string]int{
|
||||
CYAN_BLUE_RGB: GADGET_CYAN_BLUE,
|
||||
PURPLE_RGB: GADGET_PURPLE,
|
||||
}
|
||||
|
||||
var ALL_COLOR = []string{RED_RGB, GREEN_RGB, BLUE_RGB, CYAN_RGB, YELLOW_RGB, CYAN_BLUE_RGB, PURPLE_RGB}
|
||||
|
||||
type ColorLight struct {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build windows && rtmidi
|
||||
// +build windows,rtmidi
|
||||
|
||||
package game
|
||||
|
||||
import (
|
||||
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
||||
)
|
||||
@@ -590,8 +590,6 @@ func (g *GMCmd) GMSetPlayerStaminaInf(userId uint32, open bool) {
|
||||
|
||||
// 系统级GM指令
|
||||
|
||||
// TODO 不知道为什么0个参数的函数会反射调用失败
|
||||
|
||||
func (g *GMCmd) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
@@ -639,10 +637,10 @@ func (g *GMCmd) AvPlayAudio(fileDataBase64 string) {
|
||||
logger.Error("file data base64 format error: %v", err)
|
||||
return
|
||||
}
|
||||
go PlayAudio(fileData)
|
||||
PlayAudio(fileData)
|
||||
}
|
||||
|
||||
func (g *GMCmd) AvStartMidiInputDev(v bool) {
|
||||
func (g *GMCmd) AvStartMidiInputDev() {
|
||||
err := StartMidiInputDev()
|
||||
if err != nil {
|
||||
logger.Error("start midi input dev error: %v", err)
|
||||
@@ -650,7 +648,7 @@ func (g *GMCmd) AvStartMidiInputDev(v bool) {
|
||||
logger.Info("start midi input dev ok")
|
||||
}
|
||||
|
||||
func (g *GMCmd) AvStopMidiInputDev(v bool) {
|
||||
func (g *GMCmd) AvStopMidiInputDev() {
|
||||
StopMidiInputDev()
|
||||
logger.Info("stop midi input dev ok")
|
||||
}
|
||||
@@ -748,7 +746,7 @@ func (g *GMCmd) SendMsgToPlayer(cmdName string, userId uint32, msgJson string) {
|
||||
GAME.SendMsg(cmdId, userId, 0, msg)
|
||||
}
|
||||
|
||||
func (g *GMCmd) StartPubg(v bool) {
|
||||
func (g *GMCmd) StartPubg() {
|
||||
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
|
||||
if err != nil {
|
||||
logger.Error("get plugin pubg error: %v", err)
|
||||
@@ -758,7 +756,7 @@ func (g *GMCmd) StartPubg(v bool) {
|
||||
pluginPubg.StartPubg()
|
||||
}
|
||||
|
||||
func (g *GMCmd) StopPubg(v bool) {
|
||||
func (g *GMCmd) StopPubg() {
|
||||
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
|
||||
if err != nil {
|
||||
logger.Error("get plugin pubg error: %v", err)
|
||||
@@ -774,13 +772,13 @@ func (g *GMCmd) SetPhysicsEngineParam(pathTracing bool) {
|
||||
engine.SetPhysicsEngineParam(pathTracing)
|
||||
}
|
||||
|
||||
func (g *GMCmd) ShowAvatarCollider(v bool) {
|
||||
func (g *GMCmd) ShowAvatarCollider() {
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
engine := world.GetBulletPhysicsEngine()
|
||||
engine.ShowAvatarCollider()
|
||||
}
|
||||
|
||||
func (g *GMCmd) AiWorldAoiDebug(v bool) {
|
||||
func (g *GMCmd) AiWorldAoiDebug() {
|
||||
aiWorld := WORLD_MANAGER.GetAiWorld()
|
||||
if aiWorld == nil {
|
||||
return
|
||||
|
||||
@@ -358,12 +358,12 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
|
||||
func (t *TickManager) onTick50MilliSecond(now int64) {
|
||||
// 音乐播放器
|
||||
for i := 0; i < len(AUDIO_CHAN); i++ {
|
||||
for i := 0; i < len(AudioChan); i++ {
|
||||
world := WORLD_MANAGER.GetAiWorld()
|
||||
GAME.SendToWorldA(world, cmd.SceneAudioNotify, 0, &proto.SceneAudioNotify{
|
||||
Type: 5,
|
||||
SourceUid: world.GetOwner().PlayerId,
|
||||
Param1: []uint32{1, <-AUDIO_CHAN},
|
||||
Param1: []uint32{1, <-AudioChan},
|
||||
Param2: nil,
|
||||
Param3: nil,
|
||||
}, 0)
|
||||
|
||||
@@ -265,7 +265,11 @@ func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) {
|
||||
return
|
||||
}
|
||||
funcName := commandText[:beginIndex]
|
||||
paramList := strings.Split(commandText[beginIndex+1:endIndex], ",")
|
||||
funcParam := commandText[beginIndex+1 : endIndex]
|
||||
paramList := make([]string, 0)
|
||||
if funcParam != "" {
|
||||
paramList = strings.Split(funcParam, ",")
|
||||
}
|
||||
commandMessageInput <- &CommandMessage{
|
||||
GMType: SystemFuncGM,
|
||||
FuncName: funcName,
|
||||
|
||||
Reference in new issue
Block a user