Skip to content

Commit

Permalink
add txalaparta to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-shepardson committed May 29, 2024
1 parent fb7a356 commit fbfe903
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/notochord/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def help():
homunculus: run the Notochord homunculus TUI
harmonizer: run the Notochord harmonizer TUI
improviser: run the Notochord improviser TUI
txalaparta: run the txalaparta app
files: show the location of Notochord models and config files on disk
""")

Expand All @@ -30,6 +31,9 @@ def _main():
if sys.argv[1] == 'improviser':
sys.argv = sys.argv[1:]
run(improviser)
if sys.argv[1] == 'txalaparta':
sys.argv = sys.argv[1:]
run(txalaparta)
if sys.argv[1] == 'files':
d = Notochord.user_data_dir()
print(d)
Expand Down
3 changes: 2 additions & 1 deletion src/notochord/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .server import main as server
from .harmonizer import main as harmonizer
from .improviser import main as improviser
from .homunculus import main as homunculus
from .homunculus import main as homunculus
from .txalaparta import main as txalaparta
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from rich.panel import Panel
from rich.pretty import Pretty
from textual.reactive import reactive
from textual.widgets import Header, Footer, Static, Button, TextLog
from textual.widgets import Header, Footer, Static, Button, Log

### def TUI components ###
class NotoLog(TextLog):
class NotoLog(Log):
value = reactive('')
def watch_value(self, time: float) -> None:
self.write(self.value)
Expand Down Expand Up @@ -60,7 +60,7 @@ def compose(self):
### end def TUI components###

def main(
checkpoint="artifacts/noto-txala-011-0020.ckpt", # Notochord checkpoint
checkpoint="txala-latest.ckpt", # Notochord checkpoint
player_config:Dict[int,int]=None, # map MIDI channel : GM instrument
noto_config:Dict[int,int]=None, # map MIDI channel : GM instrument
pitch_set=(41,43,45), # MIDI pitches used
Expand Down Expand Up @@ -97,7 +97,8 @@ def main(
use_tui=True, # run textual UI
predict_player=True, # forecasted next events can be for player (preserves model distribution, but can lead to Notochord deciding not to play)
auto_query=True, # query notochord whenever it is unmuted and there is no pending event. generally should be True except for testing purposes.
testing=False
testing=False,
verbose=0
):
"""
Args:
Expand Down Expand Up @@ -252,7 +253,8 @@ def play_event(event, channel, feed=True, send=True, tag=None, memo=None):
state['run_length'] = 1

state['last_side'] = side
print(f'{state["run_length"]=}')
if verbose > 0:
print(f'{state["run_length"]=}')

# send out as MIDI
if send:
Expand Down Expand Up @@ -309,8 +311,9 @@ def noto_query(delay=0):
# print(counts)
player_count = sum(counts[i] for i in player_map.insts)
noto_count = sum(counts[i] for i in noto_map.insts)
print(f'player: {player_count}')
print(f'noto: {noto_count}')
if verbose > 0:
print(f'player: {player_count}')
print(f'noto: {noto_count}')
total_count = player_count + noto_count

all_insts = noto_map.insts
Expand All @@ -320,7 +323,8 @@ def noto_query(delay=0):
steer_time = 1-controls.get('steer_rate', 0.5)
tqt = (max(0,steer_time-0.5), min(1, steer_time+0.5))

print(tqt)
if verbose > 1:
print(tqt)

# if using nominal time,
# *subtract* estimated feed latency to min_time; (TODO: really should
Expand All @@ -346,7 +350,8 @@ def noto_query(delay=0):
if len(insts)==0:
insts = all_insts

print(f'{insts=}')
if verbose > 1:
print(f'{insts=}')

# bal_insts = set(counts.index[counts <= counts.min()+n_margin])
# if balance_sample and len(bal_insts)>0:
Expand All @@ -371,7 +376,8 @@ def noto_query(delay=0):

max_t = None if max_time is None else max(max_time, min_time+0.2)

print(min_time, max_t)
if verbose > 1:
print(min_time, max_t)

pending.event = query_method(
include_pitch=pitch_set,
Expand Down Expand Up @@ -419,7 +425,8 @@ def _(msg):
# print(f"{controls['steer_density']=}")
if msg.control==3:
controls['steer_rate'] = msg.value/127
print(f"{controls['steer_rate']=}")
if verbose > 0:
print(f"{controls['steer_rate']=}")

if msg.control==4:
noto_reset()
Expand Down
11 changes: 9 additions & 2 deletions src/notochord/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,19 +1207,26 @@ def from_checkpoint(cls, path):
path: file path to Notochord model
"""
if path=="notochord-latest.ckpt":
url = 'https://github.com/Intelligent-Instruments-Lab/iil-python-tools/releases/download/notochord-v0.4.0/notochord_lakh_50G_deep.pt'
elif path=="txala-latest.ckpt":
url = 'https://github.com/Intelligent-Instruments-Lab/notochord/releases/download/notochord-v0.5.4/noto-txala-011-0020.ckpt'
else:
url = None

if url is not None:
d = Notochord.user_data_dir()
path = d / path
# maybe download
if not path.is_file():
while True:
answer = input("Do you want to download a notochord model? (y/n)")
if answer.lower() in ["y","yes"]:
download_url('https://github.com/Intelligent-Instruments-Lab/iil-python-tools/releases/download/notochord-v0.4.0/notochord_lakh_50G_deep.pt', path)
download_url(url, path)
print(f'saved to {path}')
break
if answer.lower() in ["n","no"]:
break
# path =
# path =
checkpoint = torch.load(path, map_location=torch.device('cpu'))
model = cls(**checkpoint['kw']['model'])
model.load_state_dict(checkpoint['model_state'], strict=False)
Expand Down

0 comments on commit fbfe903

Please sign in to comment.