Skip to content

Commit

Permalink
Merge pull request #421 from shorepine/web
Browse files Browse the repository at this point in the history
Tulip Web
  • Loading branch information
bwhitman authored Nov 23, 2024
2 parents 7c69cc3 + d721921 commit 4bcab76
Show file tree
Hide file tree
Showing 66 changed files with 17,289 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tulip/macos/dist
tulip/macos/lextab.py
tulip/macos/yacctab.py
tulip/linux/build-standard
tulip/web/build-standard
tulip/linux/dev
tulip/ios/build-standard
tulip/esp32s3/managed_components
Expand Down
2 changes: 1 addition & 1 deletion amy
6 changes: 3 additions & 3 deletions tulip/fs/ex/xanadu.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def broken_chord(base_pitch, intervals, start_time, **kwargs):

wait_for(53000)
# Crude fade-out.
for i in range(10):
amy.volume(1 - i / 10)
time.sleep(0.1)
#for i in range(10):
# amy.send(volume=1 - i / 10)
# time.sleep(0.1)

midi.Synth.reset()

10 changes: 9 additions & 1 deletion tulip/release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# This script cleans, builds and uploads binaries for the 4 supported Tulip CC versions
# It also does this for Tulip Desktop macOS.
# It also does this for Tulip Desktop macOS and Tulip Web.

# call it like ./release.sh v-jan-2024 upload , where v-jan-2024 is a github release tag
# and upload is one of [sys, upload, test]
Expand Down Expand Up @@ -65,6 +65,14 @@ if [ "$TYPE" == "upload" ]; then
fi
cd ..

# Now do web
cd ../web
make clean
./build.sh
if [ "$TYPE" == "upload" ]; then
git commit -a -m "deploying Tulip Web"; git push -u origin HEAD; gh pr create -f; gh pr merge -m
fi
cd ..



Expand Down
5 changes: 0 additions & 5 deletions tulip/shared/alles.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ void run_alles() {

esp_amy_init();
amy_reset_oscs();
// Schedule a "turning on" sound
bleep();
//
// Spin this core until the power off button is pressed, parsing events and making sounds
//while(status & RUNNING) {
Expand All @@ -238,9 +236,6 @@ void * alles_start(void *vargs) {
alles_local_ip[0] = 0;
unix_amy_init();
amy_reset_oscs();
// Schedule a "turning on" sound
// We don't do this by default on tulip desktop as all threads start at once and it makes the bleep sound bad
bleep();
// Spin this core until the power off button is pressed, parsing events and making sounds
while(status & RUNNING) {
delay_ms(10);
Expand Down
16 changes: 13 additions & 3 deletions tulip/shared/desktop/unix_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ int8_t compute_viewport(uint16_t tw, uint16_t th, int8_t resize_tulip) {
viewport.w = (int)((float)tulip_rect.w * w_ratio);
viewport.h = (int)((float)tulip_rect.h * h_ratio);
viewport.x = (sw - viewport.w) / 2;

return 1; // ok
}

Expand All @@ -173,6 +172,7 @@ int unix_display_draw() {
frame_ticks = get_ticks_ms();




uint8_t *pixels;
int pitch;
Expand Down Expand Up @@ -200,14 +200,15 @@ int unix_display_draw() {

SDL_UnlockTexture(framebuffer);

#ifndef __EMSCRIPTEN__
SDL_RenderPresent(default_renderer);

#endif

// Clean up and show
SDL_UpdateWindowSurface(window);

display_frame_done_generic();

// Are we restarting the display for a mode change, or quitting
if(unix_display_flag < 0) {
destroy_window();
Expand All @@ -219,6 +220,9 @@ int unix_display_draw() {
}

}



return get_ticks_ms() - frame_ticks;
}

Expand All @@ -244,6 +248,12 @@ void init_window() {
// If this is not set it prevents sleep on a mac (at least)
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
SDL_SetWindowTitle(window, "Tulip Desktop");

#ifdef __EMSCRIPTEN__ // Tulip web deskop
const int simulate_infinite_loop = 0; // call the function repeatedly
const int fps = 0; // call the function as fast as the browser wants to render (typically 60fps)
// emscripten_set_main_loop(show_frame, NULL, fps, simulate_infinite_loop);
#endif
}


Expand Down
2 changes: 1 addition & 1 deletion tulip/shared/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void display_tfb_str(unsigned char*str, uint16_t len, uint8_t format, uint8_t fg
}


extern float unix_display_set_clock(uint8_t mhz);
extern void unix_display_set_clock(uint8_t mhz);
void display_set_clock(uint8_t mhz) {
if(mhz > 1 && mhz < 50) {
#ifdef ESP_PLATFORM
Expand Down
19 changes: 16 additions & 3 deletions tulip/shared/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void callback_midi_message_received(uint8_t *data, size_t len) {
if (midi_queue_tail == midi_queue_head) {
// Queue wrap, drop oldest item.
midi_queue_head = (midi_queue_head + 1) % MIDI_QUEUE_DEPTH;
fprintf(stderr, "dropped midi message\n");
//fprintf(stderr, "dropped midi message\n");
}

// We tell Python that a MIDI message has been received
Expand Down Expand Up @@ -125,6 +125,11 @@ void convert_midi_bytes_to_messages(uint8_t * data, size_t len, uint8_t usb) {
}

}
void process_single_midi_byte(uint8_t byte) {
uint8_t data[1];
data[0] = byte;
convert_midi_bytes_to_messages(data, 1, 1);
}


void midi_local(uint8_t * bytes, uint16_t len) {
Expand Down Expand Up @@ -210,9 +215,17 @@ void run_midi() {
// defined in virtualmidi.m
#else

// This is MIDI out on tulip desktop that is NOT macos... not supported
// This is MIDI out on tulip desktop that is NOT macos... web or linux
void midi_out(uint8_t * bytes, uint16_t len) {
// nothing yet
#ifdef __EMSCRIPTEN__
EM_ASM(
if(midiOutputDevice != null) {
midiOutputDevice.send(HEAPU8.subarray($0, $0 + $1));
}, bytes, len
);
#else
// nothing yet for linux
#endif
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion tulip/shared/midi.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// midi.h
#include "alles.h"
#ifdef ESP_PLATFORM
#include "alles.h"
#include "soc/uart_reg.h"
extern QueueHandle_t uart_queue;
#else
Expand All @@ -10,6 +10,7 @@ extern QueueHandle_t uart_queue;
#include "py/mphal.h"
#include "py/runtime.h"
void convert_midi_bytes_to_messages(uint8_t * data, size_t len, uint8_t usb);
void process_single_midi_byte(uint8_t byte);
extern mp_obj_t midi_callback;


Expand Down
23 changes: 18 additions & 5 deletions tulip/shared/modtulip.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "bresenham.h"
#include "extmod/vfs.h"
#include "py/stream.h"
#ifndef __EMSCRIPTEN__
#include "alles.h"
#endif
#include "midi.h"
#include "ui.h"
#include "tsequencer.h"
#include "ui.h"
#include "keyscan.h"
#include "genhdr/mpversion.h"

Expand All @@ -27,7 +29,7 @@

// tulip.display_clock(18)
// clock = tulip.display_clock()
extern float unix_display_set_clock();
extern void unix_display_set_clock(uint8_t);
extern void display_start();
extern void display_stop();
extern void save_tfb();
Expand Down Expand Up @@ -394,6 +396,8 @@ STATIC mp_obj_t tulip_board(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_str("N32R8", strlen("N32R8"));
#elif defined TULIP_DESKTOP
return mp_obj_new_str("DESKTOP", strlen("DESKTOP"));
#elif defined TULIP_WEB
return mp_obj_new_str("WEB", strlen("WEB"));
#else
return mp_obj_new_str("OTHER", strlen("OTHER"));
#endif
Expand Down Expand Up @@ -461,7 +465,8 @@ STATIC mp_obj_t tulip_defer(size_t n_args, const mp_obj_t *args) {
if(index>=0) {
defer_callbacks[index] = args[0];
defer_args[index] = args[1];
defer_sysclock[index] = amy_sysclock() + mp_obj_get_int(args[2]);
defer_sysclock[index] = get_ticks_ms() + mp_obj_get_int(args[2]);

} else {
mp_raise_ValueError(MP_ERROR_TEXT("No more defer slots available"));
}
Expand Down Expand Up @@ -856,7 +861,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_int_screenshot_obj, 1, 1, tulip


extern void mcast_send(char*, uint16_t len);

#ifndef __EMSCRIPTEN__
STATIC mp_obj_t tulip_alles_send(size_t n_args, const mp_obj_t *args) {
if(n_args > 1) {
if(mp_obj_get_int(args[1])) { // mesh
Expand Down Expand Up @@ -913,6 +918,8 @@ STATIC mp_obj_t tulip_set_quartet(size_t n_args, const mp_obj_t *args) {
}

STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_set_quartet_obj, 1, 1, tulip_set_quartet);
#endif


STATIC mp_obj_t tulip_brightness(size_t n_args, const mp_obj_t *args) {
if(n_args > 0) {
Expand Down Expand Up @@ -1075,6 +1082,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_cpu_obj, 0, 1, tulip_cpu);

#ifndef ESP_PLATFORM
#ifndef __linux__
#ifndef __EMSCRIPTEN__
extern char* get_tulip_home_path();
STATIC mp_obj_t tulip_app_path(size_t n_args, const mp_obj_t *args) {
char * path = get_tulip_home_path();
Expand All @@ -1084,6 +1092,7 @@ STATIC mp_obj_t tulip_app_path(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_app_path_obj, 0, 0, tulip_app_path);
#endif
#endif
#endif

STATIC mp_obj_t tulip_bg_bezier(size_t n_args, const mp_obj_t *args) {
uint16_t x0 = mp_obj_get_int(args[0]);
Expand Down Expand Up @@ -1303,12 +1312,14 @@ STATIC const mp_rom_map_elem_t tulip_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_key_editor), MP_ROM_PTR(&tulip_key_editor_obj) },
{ MP_ROM_QSTR(MP_QSTR_activate_editor), MP_ROM_PTR(&tulip_activate_editor_obj) },
{ MP_ROM_QSTR(MP_QSTR_int_screenshot), MP_ROM_PTR(&tulip_int_screenshot_obj) },
#ifndef __EMSCRIPTEN__
{ MP_ROM_QSTR(MP_QSTR_multicast_start), MP_ROM_PTR(&tulip_multicast_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_alles_send), MP_ROM_PTR(&tulip_alles_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_alles_map), MP_ROM_PTR(&tulip_alles_map_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_quartet), MP_ROM_PTR(&tulip_set_quartet_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&tulip_brightness_obj) },
{ MP_ROM_QSTR(MP_QSTR_rgb332_565), MP_ROM_PTR(&tulip_rgb332_565_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_quartet), MP_ROM_PTR(&tulip_set_quartet_obj) },
{ MP_ROM_QSTR(MP_QSTR_keys), MP_ROM_PTR(&tulip_keys_obj) },
{ MP_ROM_QSTR(MP_QSTR_touch), MP_ROM_PTR(&tulip_touch_obj) },
{ MP_ROM_QSTR(MP_QSTR_touch_delta), MP_ROM_PTR(&tulip_touch_delta_obj) },
Expand Down Expand Up @@ -1340,9 +1351,11 @@ STATIC const mp_rom_map_elem_t tulip_module_globals_table[] = {
// Special platform specific things
#ifndef ESP_PLATFORM
#ifndef __linux__
#ifndef __EMSCRIPTEN__
{ MP_ROM_QSTR(MP_QSTR_app_path), MP_ROM_PTR(&tulip_app_path_obj) },
#endif
#endif
#endif

};

Expand Down
19 changes: 19 additions & 0 deletions tulip/shared/polyfills.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
// free(?)
// thread / xtaskCreate

#ifdef AMY_IS_EXTERNAL
void * malloc_caps(uint32_t size, uint32_t flags) {
#ifdef ESP_PLATFORM
//fprintf(stderr, "allocing size %ld flags %ld\n", size, flags);
return heap_caps_malloc(size, flags);
#else
// ignore flags
return malloc(size);
#endif
}
#endif


#ifndef ESP_PLATFORM
Expand Down Expand Up @@ -45,7 +56,11 @@ void delay_ms(uint32_t ms) {
#ifdef ESP_PLATFORM
vTaskDelay(ms / portTICK_PERIOD_MS);
#else
#ifndef __EMSCRIPTEN__
usleep(ms * 1000);
#else
// nothing
#endif
#endif
}

Expand All @@ -68,7 +83,11 @@ int64_t get_time_ms() {
return mp_hal_ticks_ms(); // a large number
}
int32_t get_ticks_ms() {
#ifndef __EMSCRIPTEN__
return amy_sysclock(); // based on audio driver
#else
return mp_hal_ticks_ms();
#endif
}

void *calloc_caps(uint32_t align, uint32_t count, uint32_t size, uint32_t flags) {
Expand Down
2 changes: 2 additions & 0 deletions tulip/shared/polyfills.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <stdint.h>
#include "py/mphal.h"
#ifndef __EMSCRIPTEN__
#include "amy.h"
#endif
#ifdef ESP_PLATFORM
// not sure, maybe esp includes?
extern void esp32s3_display_start();
Expand Down
Loading

0 comments on commit 4bcab76

Please sign in to comment.