Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
import gc
import uos
import tulip, sys, midi, synth, amy, world, sequencer
from upysh import *
from tulip import board
if board()!="AMYBOARD" and board()!="AMYBOARD_WEB" and board()!="AMYBOARD_VCV":
from tulip import edit, run
else:
if board()=="AMYBOARD":
import amyboard
amyboard.mount_sd()
edit = amyboard.edit
elif board()=="AMYBOARD_VCV":
import amyboard
if board()=="WEB" or board()=="AMYBOARD_WEB":
def webnyi():
return "This function is not available on Tulip Web"
import world_web as world
input = webnyi()
else:
import world
# This _boot runs both desktop and esp32s3
try:
from esp32 import Partition
try:
s = Partition.find(Partition.TYPE_DATA, label="system")[0]
u = Partition.find(Partition.TYPE_DATA, label="vfs")[0]
uos.mount(s,"/sys")
uos.mount(u,"/user")
cd('/user')
sys.path.append("/sys/ex")
except:
print("Tulip flash not setup properly. Try resetting the device.")
try:
currentPartition = Partition(Partition.RUNNING)
currentPartition.mark_app_valid_cancel_rollback()
except OSError:
# this is you booting a non-OTA esp32 device. it's ok!
pass
except ImportError:
# Not a hardware Tulip
try:
tulipcc = tulip.root_dir()
if not tulip.exists(tulipcc):
mkdir(tulipcc)
if tulip.board()=='AMYBOARD_VCV':
try:
mkdir(tulipcc+"user")
except OSError:
pass
# On Desktop, we can put sys in sys/ and user in user/
if tulip.board()=='DESKTOP':
try:
mkdir(tulipcc+"sys")
tulip.desktop_copy_sys(tulipcc+"sys")
except OSError:
# already exists, do nothing
pass
try:
mkdir(tulipcc+"user")
except OSError:
# Already exists, don't do anything
pass
cd(tulip.root_dir()+"user")
tulip.add_to_bootpy("# boot.py\n# Put anything here you want to run on Tulip startup\n", only_first_create=True)
sys.path.append("../sys/ex")
except Exception as e:
sys.print_exception(e)
# Probably iOS
cd(tulip.app_path())
# Make sure user/lib exists and add it to sys.path
libdir = tulip.root_dir()+"user/lib"
if not tulip.exists(libdir):
mkdir(libdir)
sys.path.append(libdir)
# Remove other ones
try:
sys.path.remove('/lib')
except ValueError:
pass
try:
sys.path.remove('~/.micropython/lib')
except ValueError:
pass
gc.collect()
# Set up audio/midi.
if tulip.board() == "WEB" or tulip.board()=="AMYBOARD_WEB":
amy.AMY_SAMPLE_RATE=48000
# Override send & bleep are done from JS on web because of click-to-start audio.
else:
amy.AMY_SAMPLE_RATE=44100
# Nothing to override: amy's own dispatch already resolves _send_wire to
# tulip.amy_send here (amy_c_api_mp.inc). Installing the platform default
# in amy.override_send would only make it look like the user redirected
# AMY elsewhere, which is how transfer chunks lost their sysex marking and
# got parsed as wire commands (amy #1045). override_send stays free for
# what it's for -- pointing AMY at another board over midi.sysex_amy/i2c.
# amy.message() in C: tulip.amy_message() (amy_connector.c) builds the same
# wire string several times faster -- a table walk into a stack buffer instead
# of per-argument map slicing and `+=`, which all allocate. Installed over
# amy.message here so every amy.send() on every target gets it; the Python
# original is captured FIRST and the fallback goes to it by name, or the
# fallback would find this function again and recurse.
#
# The C side returns None for anything it does not reproduce exactly (an
# unknown keyword, a numeric string where an int was meant, an overlong
# message) and the Python original then runs -- and raises whatever it was
# going to raise. Kwarg combos that amy.message() warns or errors about while
# amy.show_warnings is set go straight to Python so those diagnostics still
# fire.
_py_amy_message = amy.message
amy._py_message = _py_amy_message # the original, reachable for tests/debugging
def _c_amy_message(**kwargs):
if amy.show_warnings and ('patch_string' in kwargs or 'num_partials' in kwargs or
('voices' in kwargs and ('preset' in kwargs or 'synth' in kwargs))):
return _py_amy_message(**kwargs)
m = tulip.amy_message(**kwargs)
if m is None:
return _py_amy_message(**kwargs)
return m
amy.message = _c_amy_message
if board() == "AMYBOARD" or board()=="AMYBOARD_WEB" or board()=="AMYBOARD_VCV":
import amyboard
amyboard.ensure_user_environment()
amyboard.init_display()
if board() == "AMYBOARD":
amyboard.start_amy()
# Run the self-test if the boot button is now held down.
import self_test
self_test.self_test_if_button()
if board() == "AMYBOARD_VCV":
# In-process AMY was started by the Rack module before MicroPython booted.
amyboard.start_amy()
# We don't do most of Tulip's MIDI, but setup the MIDI callback hook so midi.add_callback(fn) will work.
if board() == "AMYBOARD" or board() == "AMYBOARD_WEB" or board() == "AMYBOARD_VCV":
tulip.midi_callback(midi.c_fired_midi_event)
if board() != "AMYBOARD" and board() != "AMYBOARD_WEB" and board() != "AMYBOARD_VCV":
midi.setup() # Just mirrors the setup mostly managed by AMY for Tulip-REPL systems.
a2ffd7aadThis file is pinned to the selected release. Download the original to open it in your design tool.