Changeset 9ddbf3e in buchla-emu


Ignore:
Timestamp:
02/24/2018 06:51:40 PM (6 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
2cd18e3
Parents:
77d8df8
Message:

Code review changes.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • .cproject

    r77d8df8 r9ddbf3e  
    2525                                                        </tool>
    2626                                                        <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.862022870" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
    27                                                                 <option id="gnu.c.compiler.option.include.paths.2032588655" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
     27                                                                <option id="gnu.c.compiler.option.include.paths.2032588655" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
    2828                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/buchla-emu/cpu}&quot;"/>
    2929                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/buchla-emu/emu}&quot;"/>
    3030                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/buchla-emu/build}&quot;"/>
    3131                                                                        <listOptionValue builtIn="false" value="/opt/sdl2/include"/>
     32                                                                        <listOptionValue builtIn="false" value="/opt/rtmidi/include"/>
    3233                                                                </option>
    3334                                                                <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1138147073" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
  • .settings/language.settings.xml

    r77d8df8 r9ddbf3e  
    66                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
    77                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
    8                         <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-521499554224989883" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
     8                        <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="882153106844088736" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
    99                                <language-scope id="org.eclipse.cdt.core.gcc"/>
    1010                                <language-scope id="org.eclipse.cdt.core.g++"/>
  • Makefile

    r77d8df8 r9ddbf3e  
    5959                                -framework AudioToolbox \
    6060                                -framework Carbon \
    61                                 -framework CoreMIDI \
    6261                                -framework CoreAudio \
    6362                                -framework CoreFoundation \
    6463                                -framework CoreGraphics \
     64                                -framework CoreMIDI \
    6565                                -framework CoreVideo \
    6666                                -framework ForceFeedback \
     
    7070else
    7171FLAGS_EMU +=    -D EMU_WIN
    72 FLAGS_LNK :=    $(FLAGS) -Wall -Wextra -static -static-libstdc++
     72FLAGS_LNK :=    $(FLAGS) -Wall -Wextra -static
    7373LIBS :=                 -l mingw32 \
    7474                                $(SDL2_LIB)/libSDL2.a \
  • emu/all.h

    r77d8df8 r9ddbf3e  
    3030#include <SDL2/SDL_net.h>
    3131#include <SDL2/SDL_ttf.h>
     32
     33// work around RtMidi's C++-isms
     34
     35#pragma GCC diagnostic push
     36#pragma GCC diagnostic ignored "-Wstrict-prototypes"
     37
     38typedef struct RtMidiWrapper RtMidiWrapper;
     39
     40#include <rtmidi/rtmidi_c.h>
     41
     42#pragma GCC diagnostic pop
    3243
    3344#define inf(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__);
     
    6576extern const char *font;
    6677
     78extern int32_t mid_port;
     79
    6780extern SDL_atomic_t run;
    6881
     
    7083extern uint32_t ser_win;
    7184extern uint32_t lcd_win;
    72 
    73 extern uint32_t mid_port;
    7485
    7586extern void sdl_init(void);
  • emu/main.c

    r77d8df8 r9ddbf3e  
    4343const char *font = "ttf/vera-sans-mono.ttf";
    4444
     45int32_t mid_port = -1;
     46
    4547SDL_atomic_t run;
    4648
    47 uint32_t mid_port = 0;
    48 
    4949static void usage(FILE *fh)
    5050{
    51         fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font] [-m midiport] \n");
    52         fprintf(fh, "where comp is one of: ");
     51        fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font] [-m port]\n");
     52        fprintf(fh, "with\n");
     53        fprintf(fh, "  comp - one of: ");
    5354
    5455        for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
     
    5758
    5859        fprintf(fh, "all\n");
    59         fprintf(fh, "and midiport is the number of the desired MIDI port\n");
    60         fprintf(fh, "list all available MIDI ports with: buchla [-m list]\n");
     60        fprintf(fh, "  bios - BIOS ROM file (default: bios.abs)\n");
     61        fprintf(fh, "  disk - disk image file (default: buchla.disk)\n");
     62        fprintf(fh, "  font - console and LCD font (default: ttf/vera-sans-mono.ttf)\n");
     63        fprintf(fh, "  port - number of the desired MIDI port (default: 0)\n");
     64        fprintf(fh, "         \"list\" instead of a port number lists available ports\n");
    6165}
    6266
     
    145149                                mid_list();
    146150                                exit(0);
    147                                 continue;
    148                         }
    149 
    150                         // TODO: Assign midi port number
    151                          mid_port = (uint32_t) atoi(argv[i]);
     151                        }
     152
     153                        char *end;
     154                        int64_t tmp = strtol(argv[i], &end, 10);
     155
     156                        if (*end != 0 || tmp < 0 || tmp > 15) {
     157                                usage(stderr);
     158                                fprintf(stderr, "invalid argument to -m: %s\n", argv[i]);
     159                                exit(1);
     160                        }
     161
     162                        mid_port = (int32_t)tmp;
    152163                        continue;
    153164                }
  • emu/mid.c

    r77d8df8 r9ddbf3e  
    11/*
    2  *  Copyright (C) 2017 The Contributors
     2 *  Copyright (C) 2017-2018 The Contributors
    33 *
    44 *  This program is free software: you can redistribute it and/or modify
     
    1717
    1818#include <all.h>
    19 #include <rtmidi/rtmidi_c.h>
    2019
    2120#define ver(...) _ver(mid_verbose, 0, __VA_ARGS__)
    2221#define ver2(...) _ver(mid_verbose, 1, __VA_ARGS__)
    2322#define ver3(...) _ver(mid_verbose, 2, __VA_ARGS__)
     23
     24int32_t mid_verbose = 0;
    2425
    2526#define REG_IER_ISR 0
     
    4546};
    4647
    47 int32_t mid_verbose = 0;
    48 
    49 struct RtMidiWrapper* mid_in;
     48static struct RtMidiWrapper *mid_in = NULL;
    5049
    5150static void xmit(int32_t un)
     
    7473}
    7574
    76 static void out_lk(int32_t un, uint8_t c)
    77 {
     75static void out(int32_t un, uint8_t c)
     76{
     77        if (SDL_LockMutex(cpu_mutex) < 0) {
     78                fail("SDL_LockMutex() failed: %s", SDL_GetError());
     79        }
     80
    7881        int32_t i = state[un].buf_hd;
    7982        ver2("mid out %d %d 0x%02x", state[un].buf_tl, i, c);
     
    9093                xmit(un);
    9194        }
    92 }
    93 
    94 static void out(int32_t un, uint8_t c)
    95 {
    96         if (SDL_LockMutex(cpu_mutex) < 0) {
    97                 fail("SDL_LockMutex() failed: %s", SDL_GetError());
    98         }
    99 
    100         out_lk(un, c);
    10195
    10296        if (SDL_UnlockMutex(cpu_mutex) < 0) {
     
    10599}
    106100
    107 static void mid_callback(double timeStamp, const unsigned char* message, size_t size, void *userData) {
    108         (void) size;
    109         (void) userData;
    110 
    111         ver2("Timestamp %f\n", timeStamp);
    112 
    113         for (uint8_t i = 0; i < sizeof(message); i++) {
    114                 ver2("Message %i %u", i, (uint8_t) message[i]);
    115                 out(0, message[i]);
     101static void callback(double time, const uint8_t *midi, void *data)
     102{
     103        (void)data;
     104
     105        int32_t len;
     106
     107        switch (midi[0] & 0xf0) {
     108        case 0x80: // note on
     109        case 0x90: // note off
     110        case 0xa0: // polyphonic key pressure
     111        case 0xb0: // control change
     112        case 0xe0: // pitch bend change
     113                len = 3;
     114                break;
     115
     116        case 0xc0: // program change
     117        case 0xd0: // channel pressure
     118                len = 2;
     119                break;
     120
     121        case 0xf0:
     122                switch (midi[0]) {
     123                case 0xf0: // system exclusive
     124                case 0xf4: // undefined
     125                case 0xf5: // undefined
     126                case 0xf7: // end of exclusive
     127                case 0xf9: // undefined
     128                case 0xfd: // undefined
     129                        len = -1;
     130                        break;
     131
     132                case 0xf1: // MIDI time code quarter frame
     133                case 0xf3: // song select
     134                        len = 2;
     135                        break;
     136
     137                case 0xf2: // song position pointer
     138                        len = 3;
     139                        break;
     140
     141                case 0xf6: // tune request
     142                case 0xf8: // timing clock
     143                case 0xfa: // start
     144                case 0xfb: // continue
     145                case 0xfc: // stop
     146                case 0xfe: // active sensing
     147                case 0xff: // reset
     148                        len = 1;
     149                        break;
     150                }
     151
     152                break;
     153        }
     154
     155        ver2("time %f", time);
     156
     157        for (int32_t i = 0; i < len; ++i) {
     158                ver2("midi[%d] 0x%02x", i, midi[i]);
     159                out(0, midi[i]);
    116160        }
    117161}
     
    121165        ver("mid init");
    122166
     167        if (mid_port < 0) {
     168                ver("no MIDI requested");
     169                return;
     170        }
     171
    123172        mid_in = rtmidi_in_create_default();
    124         ver2("%p", mid_in->ptr);
    125         // check if null
    126 
    127         uint32_t portcount = rtmidi_get_port_count(mid_in);
    128         if (portcount == 0) {
     173
     174        if (!mid_in->ok) {
     175                fail("rtmidi_in_create_default() failed: %s", mid_in->msg);
     176        }
     177
     178        int32_t n_ports = (int32_t)rtmidi_get_port_count(mid_in);
     179
     180        if (n_ports == 0) {
     181                inf("no MIDI ports\n");
     182                rtmidi_in_free(mid_in);
    129183                mid_in = NULL;
    130                 ver2("No MIDI ports\n");
    131                 return;
    132         }
    133 
    134         if (mid_port > portcount) {
    135                 mid_in = NULL;
    136                 ver2("Selected MIDI port larger than number of midi ports");
    137                 return;
    138         }
    139 
    140         rtmidi_open_port(mid_in, mid_port, rtmidi_get_port_name(mid_in, mid_port));
    141 
    142         if(mid_in->ok == 0) {
    143                 fail("Failed to open MIDI port");
    144         }
    145 
    146         ver2("Using MIDI port %u", mid_port);
    147 
    148         rtmidi_in_set_callback(mid_in, mid_callback, mid_in->data);
    149 
    150         if(mid_in->ok == 0) {
    151                 fail("Failed to set MIDI Callback");
     184                return;
     185        }
     186
     187        if (mid_port >= n_ports) {
     188                fail("invalid MIDI port %d selected (%d available)", mid_port, n_ports);
     189        }
     190
     191        const char *name = rtmidi_get_port_name(mid_in, (uint32_t)mid_port);
     192        rtmidi_open_port(mid_in, (uint32_t)mid_port, name);
     193
     194        if (!mid_in->ok) {
     195                fail("error while opening MIDI port %d (%s): %s", mid_port, name, mid_in->msg);
     196        }
     197
     198        inf("using MIDI port %d (%s)", mid_port, name);
     199
     200        rtmidi_in_set_callback(mid_in, callback, mid_in->data);
     201
     202        if (!mid_in->ok) {
     203                fail("rtmidi_in_set_callback() failed: %s", mid_in->msg);
    152204        }
    153205}
     
    155207void mid_quit(void)
    156208{
    157         if(mid_in) {
    158                 rtmidi_close_port(mid_in);
    159                 rtmidi_in_free(mid_in);
    160         }
    161 
    162209        ver("mid quit");
     210
     211        if (mid_in == NULL) {
     212                return;
     213        }
     214
     215        rtmidi_close_port(mid_in);
     216        rtmidi_in_free(mid_in);
    163217}
    164218
     
    237291}
    238292
    239 void mid_list(void) {
     293void mid_list(void)
     294{
    240295        mid_in = rtmidi_in_create_default();
    241296
    242         uint32_t portcount = rtmidi_get_port_count(mid_in);
    243 
    244         if (portcount == 0) {
    245                 mid_in = NULL;
    246                 ver2("no MIDI ports\n");
    247                 return;
    248         }
    249 
    250         fprintf(stdout, "the following MIDI ports are available:\n");
    251 
    252         for (uint32_t i = 0; i < portcount; i++) {
    253                 fprintf(stdout, "port %d: %s\n", i, rtmidi_get_port_name(mid_in, i));
     297        if (!mid_in->ok) {
     298                fprintf(stderr, "rtmidi_in_create_default() failed: %s\n", mid_in->msg);
     299                return;
     300        }
     301
     302        uint32_t n_ports = rtmidi_get_port_count(mid_in);
     303
     304        if (n_ports == 0) {
     305                fprintf(stdout, "no available MIDI ports\n");
     306        }
     307        else {
     308                for (uint32_t i = 0; i < n_ports; i++) {
     309                        fprintf(stdout, "port %u: %s\n", i, rtmidi_get_port_name(mid_in, i));
     310                }
    254311        }
    255312
  • readme.txt

    r77d8df8 r9ddbf3e  
    9393  make
    9494  make install
    95  
    96   # Build and install rtmidi
    97  
     95
     96  # Build and install RtMidi
     97
    9898  tar zxvf rtmidi-3.0.0.tar.gz
    9999  cd rtmidi-3.0.0
    100100  mkdir build
    101101  cd build
    102  
     102
    103103  ../configure --prefix=/opt/rtmidi
    104  
     104
    105105  make
    106106  make install
     
    116116
    117117  * We use "--prefix=/opt/sdl2-win" instead of "--prefix=/opt/sdl2",
    118     so that the Windows versions of the libraries go to a different
    119     directory. That's where our Makefile expects to find them when
    120     cross-building.
     118    so that the Windows versions of the SDL2 libraries go to a
     119    different directory. That's where our Makefile expects to find
     120    them when cross-building.
     121
     122    Analogously, we use "--prefix=/opt/rtmidi-win" when building
     123    RtMidi.
    121124
    122125  * We additionally specify "--host=x86_64-w64-mingw32" to enable
Note: See TracChangeset for help on using the changeset viewer.