Skip to content

Commit aa1b2b7

Browse files
committed
Add example external client for testing and documentation
Provide a minimal working example of an external client that users can: - Test with: pi-pianoteq --client example_client:ExampleClient - Use as a template for custom client development - Reference when following the custom client documentation The example demonstrates all required Client abstract methods with simple console output, making it easy to understand the client lifecycle.
1 parent 6d9c2ea commit aa1b2b7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

example_client.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
Example minimal external client for Pi-Pianoteq.
3+
4+
This demonstrates the minimum required implementation for a custom client.
5+
You can test it with: pi-pianoteq --client example_client:ExampleClient
6+
"""
7+
from typing import Optional
8+
import logging
9+
10+
from pi_pianoteq.client.client import Client
11+
from pi_pianoteq.client.client_api import ClientApi
12+
13+
14+
class ExampleClient(Client):
15+
"""
16+
Minimal example client that prints to console.
17+
18+
Demonstrates the basic structure for a custom client.
19+
"""
20+
21+
def __init__(self, api: Optional[ClientApi]):
22+
"""Initialize the client in loading mode (api=None)"""
23+
super().__init__(api)
24+
print("ExampleClient initialized")
25+
26+
def set_api(self, api: ClientApi):
27+
"""Called when the API becomes available"""
28+
self.api = api
29+
print(f"ExampleClient: API ready with {len(api.get_instruments())} instruments")
30+
31+
def show_loading_message(self, message: str):
32+
"""Display loading messages during startup"""
33+
print(f"[LOADING] {message}")
34+
35+
def start(self):
36+
"""Main client loop - called after set_api()"""
37+
print("\nExampleClient started!")
38+
print("=" * 60)
39+
40+
# Show current state
41+
instrument = self.api.get_current_instrument()
42+
preset = self.api.get_current_preset()
43+
print(f"Current: {instrument.name} - {preset.name}")
44+
45+
# List available instruments
46+
print(f"\nAvailable instruments ({len(self.api.get_instruments())}):")
47+
for i, instr in enumerate(self.api.get_instruments(), 1):
48+
print(f" {i}. {instr.name}")
49+
50+
print("\nPress Ctrl+C to exit")
51+
52+
# Simple loop - just wait for interrupt
53+
try:
54+
import time
55+
while True:
56+
time.sleep(1)
57+
except KeyboardInterrupt:
58+
print("\nExampleClient shutting down...")
59+
60+
def get_logging_handler(self) -> Optional[logging.Handler]:
61+
"""Return None to use default stdout/stderr logging"""
62+
return None

0 commit comments

Comments
 (0)