Skip to content

Commit

Permalink
Can force connections
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoreno committed Dec 15, 2023
1 parent 0a0d205 commit ff34a46
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
51 changes: 50 additions & 1 deletion cli/rtpmidid-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def print_footer(self):
self.terminal_goto(1, self.height)

print(self.ANSI_BG_BLUE + self.ANSI_TEXT_BOLD + self.ANSI_TEXT_WHITE, end="")
footer_left = f"Press Ctrl-C to exit | [q]uit | [k]ill midi peer | [up] [down] to navigate |"
footer_left = f"Press Ctrl-C to exit | [q]uit | [k]ill midi peer | [c]onnect to peer | [up] [down] to navigate"
footer_right = f"| rtpmidid-cli v23.12 | (C) Coralbits 2023"
padding = self.width - len(footer_left) - len(footer_right)
self.print_padding(f"{footer_left}{' ' * padding}{footer_right}")
Expand Down Expand Up @@ -284,6 +284,55 @@ def parse_key(self, key):
self.conn.command(
{"method": "router.remove", "params": [self.selected_row["id"]]}
)
elif key == "c":
peer_id = self.dialog_ask("Connect to which peer id?")
self.conn.command(
{
"method": "router.connect",
"params": {"from": self.selected_row["id"], "to": int(peer_id)},
}
)

def set_cursor(self, x, y):
print("\033[%d;%dH" % (y, x), end="")

def dialog_ask(self, question, width=60):
# print a blue box with white text
width_2 = width // 2
start_x = self.width // 2 - width_2
start_y = self.height // 3

print(self.ANSI_BG_BLUE + self.ANSI_TEXT_WHITE + self.ANSI_TEXT_BOLD, end="")
self.terminal_goto(start_x, start_y)
self.print_padding("", width_2)
self.terminal_goto(start_x, start_y + 1)
self.print_padding(" " + question, width_2)
self.terminal_goto(start_x, start_y + 2)
self.print_padding("", width_2)
self.terminal_goto(start_x, start_y + 4)
self.print_padding("", width_2)
print(self.ANSI_RESET + self.ANSI_BG_WHITE + self.ANSI_TEXT_BLUE, end="")
self.terminal_goto(start_x, start_y + 3)
self.print_padding("", width_2)
self.set_cursor(start_x + 1, start_y + 3)

sys.stdout.flush()
answer = ""
while True:
key = self.wait_for_input()
if key == "\n":
break
elif key == "\x7f":
answer = answer[:-1]
elif key:
answer += key
self.terminal_goto(start_x, start_y + 3)
self.print_padding(" " + answer, width_2)
self.set_cursor(start_x + 1 + len(answer), start_y + 3)
sys.stdout.flush()
print(self.ANSI_RESET, end="")

return answer

def print_row(self, row):
if not row:
Expand Down
11 changes: 11 additions & 0 deletions src/control_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ std::vector<control_socket_ns::command_t> commands{
control.router->remove_peer(peer_id);
return "ok";
}},
{"router.connect",
"Connects two peers at the router. Unidirectional conneciton.",
[](control_socket_t &control, const json_t &params) {
DEBUG("Params {}", params.dump());
peer_id_t from_peer_id, to_peer_id;
from_peer_id = params["from"];
to_peer_id = params["to"];
DEBUG("Connect peers: {} -> {}", from_peer_id, to_peer_id);
control.router->connect(from_peer_id, to_peer_id);
return "ok";
}},
{"connect",
"Connect to a peer send params: [hostname] | [hostname, port] | [name, "
"hostname, port] | {\"name\": name, \"hostname\": hostname, \"port\": "
Expand Down

0 comments on commit ff34a46

Please sign in to comment.