Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for PortMidi input #17

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "3rdparty/rtmidi"]
path = 3rdparty/rtmidi
url = https://github.com/Wohlstand/rtmidi.git
[submodule "3rdparty/portmidi"]
path = 3rdparty/portmidi
url = https://github.com/PortMidi/portmidi.git
1 change: 1 addition & 0 deletions 3rdparty/portmidi
Submodule portmidi added at 392030
1 change: 0 additions & 1 deletion 3rdparty/rtmidi
Submodule rtmidi deleted from 722703
26 changes: 8 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,14 @@ endif()
include(3rdparty/Utf8Main/utf8main.cmake)

if(NOT WIN32 AND PKG_CONFIG_FOUND)
set(USE_RTMIDI TRUE)
option(USE_SYSTEM_RTMIDI "Use system libraries for RtMidi" OFF)
set(USE_PORTMIDI TRUE)
option(USE_SYSTEM_PORTMIDI "Use system libraries for PortMidi" OFF)
endif()

find_package(SDL2 REQUIRED)

if(USE_RTMIDI)
if(USE_SYSTEM_RTMIDI)
pkg_check_modules(SYSTEM_RTMIDI rtmidi REQUIRED)
else()
include(RtMidi)
endif()
if(USE_PORTMIDI)
add_subdirectory(3rdparty/portmidi)
endif()


Expand All @@ -200,8 +196,8 @@ set(SC55_SRC
src/utils/files.cpp src/utils/files.h
)

if(USE_RTMIDI)
list(APPEND SC55_SRC src/midi_rtmidi.cpp)
if(USE_PORTMIDI)
list(APPEND SC55_SRC src/midi_portmidi.cpp)
elseif(WIN32)
list(APPEND SC55_SRC src/midi_win32.cpp)
endif()
Expand All @@ -217,14 +213,8 @@ else()
target_link_libraries(nuked-sc55 PRIVATE ${SDL2_LIBRARIES})
endif()

if(USE_RTMIDI)
if(USE_SYSTEM_RTMIDI)
target_compile_options(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_CFLAGS})
target_include_directories(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_INCLUDE_DIRS})
target_link_libraries(nuked-sc55 PRIVATE ${SYSTEM_RTMIDI_LIBRARIES})
else()
target_link_libraries(nuked-sc55 PRIVATE RtMidi)
endif()
if(USE_PORTMIDI)
target_link_libraries(nuked-sc55 PRIVATE portmidi)
endif()

if(WIN32)
Expand Down
16 changes: 0 additions & 16 deletions cmake/RtMidi.cmake

This file was deleted.

79 changes: 62 additions & 17 deletions src/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void LCD_Write(uint32_t address, uint8_t data)
else if ((data & 0xff) == 0x01)
{
LCD_DD_RAM = 0;
LCD_ID = 0;
LCD_ID = 1;
memset(LCD_Data, 0x20, sizeof(LCD_Data));
}
else if ((data & 0xff) == 0x02)
Expand Down Expand Up @@ -162,20 +162,22 @@ void LCD_Write(uint32_t address, uint8_t data)
// printf("\n");
}

static const int lcd_width = 741;
static const int lcd_height = 268;
int lcd_width = 741;
int lcd_height = 268;
static const int lcd_width_max = 1024;
static const int lcd_height_max = 1024;
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_Texture *texture;

static std::string m_back_path = "back.data";

static uint32_t lcd_buffer[lcd_height][lcd_width];
static uint32_t lcd_background[lcd_height][lcd_width];
static uint32_t lcd_buffer[lcd_height_max][lcd_width_max];
static uint32_t lcd_background[268][741];

static uint32_t lcd_init = 0;

const int button_map[][2] =
const int button_map_sc55[][2] =
{
SDL_SCANCODE_Q, MCU_BUTTON_POWER,
SDL_SCANCODE_W, MCU_BUTTON_INST_ALL,
Expand All @@ -197,7 +199,25 @@ const int button_map[][2] =
SDL_SCANCODE_J, MCU_BUTTON_CHORUS_L,
SDL_SCANCODE_K, MCU_BUTTON_CHORUS_R,
SDL_SCANCODE_LEFT, MCU_BUTTON_PART_L,
SDL_SCANCODE_RIGHT, MCU_BUTTON_PART_R
SDL_SCANCODE_RIGHT, MCU_BUTTON_PART_R,
};

const int button_map_jv880[][2] =
{
SDL_SCANCODE_P, MCU_BUTTON_PREVIEW,
SDL_SCANCODE_LEFT, MCU_BUTTON_CURSOR_L,
SDL_SCANCODE_RIGHT, MCU_BUTTON_CURSOR_R,
SDL_SCANCODE_TAB, MCU_BUTTON_DATA,
SDL_SCANCODE_Q, MCU_BUTTON_TONE_SELECT,
SDL_SCANCODE_A, MCU_BUTTON_PATCH_PERFORM,
SDL_SCANCODE_W, MCU_BUTTON_EDIT,
SDL_SCANCODE_E, MCU_BUTTON_SYSTEM,
SDL_SCANCODE_R, MCU_BUTTON_RHYTHM,
SDL_SCANCODE_T, MCU_BUTTON_UTILITY,
SDL_SCANCODE_S, MCU_BUTTON_MUTE,
SDL_SCANCODE_D, MCU_BUTTON_MONITOR,
SDL_SCANCODE_F, MCU_BUTTON_COMPARE,
SDL_SCANCODE_G, MCU_BUTTON_ENTER,
};


Expand Down Expand Up @@ -326,22 +346,37 @@ void LCD_Update(void)
{
MCU_WorkThread_Lock();

if (!lcd_enable)
if (!lcd_enable && !mcu_jv880)
{
memset(lcd_buffer, 0, sizeof(lcd_buffer));
}
else
{
memcpy(lcd_buffer, lcd_background, sizeof(lcd_buffer));
if (mcu_jv880)
{
for (size_t i = 0; i < lcd_height; i++) {
for (size_t j = 0; j < lcd_width; j++) {
lcd_buffer[i][j] = 0xFF0F6FFF;
}
}
}
else
{
for (size_t i = 0; i < lcd_height; i++) {
for (size_t j = 0; j < lcd_width; j++) {
lcd_buffer[i][j] = lcd_background[i][j];
}
}
}

if (0)
if (mcu_jv880)
{
for (int i = 0; i < 4; i++)
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 20; j++)
for (int j = 0; j < 24; j++)
{
uint8_t ch = LCD_Data[i * 20 + j];
LCD_FontRenderStandard(i * 50, j * 34, ch);
uint8_t ch = LCD_Data[i * 40 + j];
LCD_FontRenderStandard(4 + i * 50, 4 + j * 34, ch);
}
}
}
Expand Down Expand Up @@ -401,14 +436,22 @@ void LCD_Update(void)

MCU_WorkThread_Unlock();

SDL_UpdateTexture(texture, NULL, lcd_buffer, lcd_width * 4);
SDL_UpdateTexture(texture, NULL, lcd_buffer, lcd_width_max * 4);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}

SDL_Event sdl_event;
while (SDL_PollEvent(&sdl_event))
{
if (sdl_event.type == SDL_KEYDOWN)
{
if (sdl_event.key.keysym.scancode == SDL_SCANCODE_COMMA)
MCU_EncoderTrigger(0);
if (sdl_event.key.keysym.scancode == SDL_SCANCODE_PERIOD)
MCU_EncoderTrigger(1);
}

switch (sdl_event.type)
{
case SDL_QUIT:
Expand All @@ -420,11 +463,13 @@ void LCD_Update(void)
{
if (sdl_event.key.repeat)
continue;

int mask = 0;
uint32_t button_pressed = (uint32_t)SDL_AtomicGet(&mcu_button_pressed);

for (size_t i = 0; i < sizeof(button_map) / sizeof(button_map[0]); i++)
auto button_map = mcu_jv880 ? button_map_jv880 : button_map_sc55;
auto button_size = (mcu_jv880 ? sizeof(button_map_jv880) : sizeof(button_map_sc55)) / sizeof(button_map_sc55[0]);
for (size_t i = 0; i < button_size; i++)
{
if (button_map[i][0] == sdl_event.key.keysym.scancode)
mask |= (1 << button_map[i][1]);
Expand Down
3 changes: 3 additions & 0 deletions src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <stdint.h>
#include <string>

extern int lcd_width;
extern int lcd_height;

void LCD_SetBackPath(const std::string &path);
void LCD_Init(void);
void LCD_UnInit(void);
Expand Down
Loading