Skip to content

Commit

Permalink
alda-lang#404 REPL :stop command fails for overly long segments
Browse files Browse the repository at this point in the history
Changed function `hasPlayer`
Add a new REPL command `stopall` that stops all player process
  • Loading branch information
MrKo777 committed Apr 16, 2022
1 parent 5acb0d5 commit 25b42fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions client/repl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ arguments will save the updated score to the same file.`,
},
},

"stopall": {
helpSummary: "Stops all player process.",
run: func(client *Client, argsString string) error {
_, err := client.sendRequest(map[string]interface{}{"op": "stopall"})
if err != nil {
return err
}

return nil
},
},

"version": {
helpSummary: "Displays the version numbers of the Alda server and client.",
run: func(client *Client, argsString string) error {
Expand Down
2 changes: 1 addition & 1 deletion client/repl/player_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (server *Server) withTransmitter(
// For practical purposes, if Port is 0, then we can be reasonably certain that
// the server doesn't have a player to talk to.
func (server *Server) hasPlayer() bool {
return server.player.Port != 0
return server.player != system.PlayerState{}
}

// The `managePlayers` loop regularly checks to see if the player process that
Expand Down
22 changes: 22 additions & 0 deletions client/repl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,28 @@ var ops = map[string]func(*Server, nREPLRequest){
server.respondDone(req, map[string]interface{}{"text": server.input})
},

"stopall": func(server *Server, req nREPLRequest) {
players := []system.PlayerState{}
knownPlayers, _ := system.ReadPlayerStates()
players = append(players, knownPlayers...)

for _, player := range players {
transmitter := transmitter.OSCTransmitter{Port: player.Port}
if err := transmitter.TransmitStopMessage(); err != nil {
log.Warn().
Interface("player", player).
Err(err).
Msg("Failed to send \"stop\" message to player process.")
} else {
log.Info().
Interface("player", player).
Msg("Sent \"stop\" message to player process.")
}
}

server.respondDone(req, nil)
},

"stop": func(server *Server, req nREPLRequest) {
if err := server.withTransmitter(
func(transmitter transmitter.OSCTransmitter) error {
Expand Down

0 comments on commit 25b42fd

Please sign in to comment.