WIP - midiwire

This commit is contained in:
severak 2019-10-11 15:24:59 +02:00
parent 3c51828400
commit dc01074ea3
6 changed files with 112 additions and 0 deletions

11
midiwire/README.md Normal file
View File

@ -0,0 +1,11 @@
# midiwire
a simple lua library for realtime MIDI.
Windows only for now. Sorry.
## resources
- https://github.com/SiENcE/lovemidi
- https://github.com/wilkie/djehuty/blob/master/binding/win32/mmsystem.d
- http://www.giordanobenicchi.it/midi-tech/lowmidi.htm

3
midiwire/build_win.bat Normal file
View File

@ -0,0 +1,3 @@
tiny_impdef lua53.dll -o lua.def
tiny_impdef winmm.dll -o winmm.def
tcc -shared midiwire.c lua.def winmm.def

56
midiwire/midiwire.c Normal file
View File

@ -0,0 +1,56 @@
#ifdef _WIN32
#include <windows.h>
#include <winuser.h>
#include <stdio.h>
#endif
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#if LUA_VERSION_NUM >= 502
# define new_lib(L, l) (luaL_newlib(L, l))
#else
# define new_lib(L, l) (lua_newtable(L), luaL_register(L, NULL, l))
#endif
#include "midiwire.h"
#include "mmsystem.h"
static int midiwire_sleep (lua_State *L) {
int ms = luaL_checkinteger(L, 1);
sleep(ms);
return 0;
}
static int midiwire_device_count (lua_State *L) {
int devices_count = midiOutGetNumDevs();
lua_pushinteger(L, devices_count);
return 1;
}
static int midiwire_name (lua_State *L) {
MIDIOUTCAPSA moc;
int port = luaL_checkinteger(L, 1);
if (!midiOutGetDevCapsA(port, &moc, sizeof(MIDIOUTCAPSA))) {
lua_pushstring(L, moc.szPname);
} else {
lua_pushnil(L);
}
return 1;
}
static const struct luaL_Reg midiwire[] = {
{"sleep", midiwire_sleep},
{"device_count", midiwire_device_count},
{"name", midiwire_name},
{NULL, NULL},
};
MIDIWIRE_EXPORT int luaopen_midiwire (lua_State *L) {
new_lib (L, midiwire);
lua_pushvalue(L, -1);
lua_setglobal(L, "midiwire");
return 1;
}

7
midiwire/midiwire.h Normal file
View File

@ -0,0 +1,7 @@
#ifdef _WIN32
#define MIDIWIRE_EXPORT __declspec (dllexport)
#else
#define MIDIWIRE_EXPORT
#endif
MIDIWIRE_EXPORT int luaopen_midiwire (lua_State *L);

21
midiwire/mmsystem.h Normal file
View File

@ -0,0 +1,21 @@
// viz https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/cca27429-5689-4a16-b2b4-9325d93e4ba2
typedef char CHAR, *PCHAR;
typedef unsigned short WORD, *PWORD, *LPWORD;
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef unsigned int MMVERSION;
// derived from https://github.com/wilkie/djehuty/blob/master/binding/win32/mmsystem.d
#define MAXPNAMELEN 32
typedef struct midi_out_capsa {
WORD wMid; /* manufacturer ID */
WORD wPid; /* product ID */
MMVERSION vDriverVersion; /* version of the driver */
CHAR szPname[MAXPNAMELEN]; /* product name (NULL terminated string) */
WORD wTechnology; /* type of device */
WORD wVoices; /* # of voices (internal synth only) */
WORD wNotes; /* max # of notes (internal synth only) */
WORD wChannelMask; /* channels used (internal synth only) */
DWORD dwSupport; /* functionality supported by driver */
} MIDIOUTCAPSA;

14
midiwire/test.lua Normal file
View File

@ -0,0 +1,14 @@
local mw = require "midiwire"
print "sleeping..."
-- mw.sleep(1000)
print "# of devices:"
print(mw.device_count())
print "ports:"
for i=0,mw.device_count()-1 do
print(i, mw.name(i))
end
print "Alles gute!"