OPL3BankEditor icon indicating copy to clipboard operation
OPL3BankEditor copied to clipboard

OPL2 hardware unit connectivity

Open Deftaudio opened this issue 4 years ago • 36 comments

Hi Vitaly, I've just built an OPL2 external board under this project https://github.com/DhrBaksteen/ArduinoOPL2 It has a capability to interface to Teensy/Arduino and act as an MIDI synthesizer, however, it has limited capability for editing. There is also a simple way to passthrough it over the serial, so it an be driven directly. https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/examples/DosBoxPassthrough/DosBoxPassthrough.ino I'd like to get it running with your editor. Would you please suggest me how to do that and if it's not possible now, add an option for forwarding all commands over a serial port?

Thank you, Andrei.

Deftaudio avatar Aug 16 '19 20:08 Deftaudio

Hi @Deftaudio. It seems quite doable. It would need to implement an interaction with the com ports on all platforms. I'll check DosBox for how it works on the computer side.

jpcima avatar Aug 16 '19 21:08 jpcima

Hi JB, that sounds fantastic, thank you.

Deftaudio avatar Aug 16 '19 21:08 Deftaudio

@Deftaudio, I think you can make your custom "liboplproxy.dll" if you running Windows: here is a code that intended to pass raw data to OPL3 chip: https://github.com/Wohlstand/OPL3BankEditor/blob/master/src/opl/chips/win9x_opl_proxy.cpp And here https://github.com/Wohlstand/OPL3BankEditor/tree/master/opl_proxy there are two variants of the same library: to use on Windows 98/ME and to use on modern Windows.

If you using Linux or macOS, I have made a small thing to allow using of native builds (make your own liboplproxy.so or liboplproxy.dylib with compatible ABI). Just now I have made a full support of OPL Proxy plugin on all operating systems.

See here the skeleton of plugin: https://github.com/Wohlstand/OPL3BankEditor/blob/master/opl_proxy/dummy-non-windows/oplproxy.c Just fill your code to send input data into your device.

Wohlstand avatar Aug 16 '19 21:08 Wohlstand

But one note: Editor is designed for OPL3 chip, and I am not sure, it will correctly work on OPL2 where there are 9 channels will be expected instead of 18 wished. I'll try to make some to support OPL2 (that needs to add one enum field into chipset which will say what chip is on the backend to change behavior).

Wohlstand avatar Aug 16 '19 21:08 Wohlstand

Vitaly, thanks a lot. I actually target OS X, but will go with anything that's easier to implement. I'm sorry, I'm far from being able to make that change. Would you, please, able to help me with serial proxy plugin?

Deftaudio avatar Aug 16 '19 21:08 Deftaudio

That would be really simple: the proxy will just stream raw <reg>=<val> pair of digits you'll need to send to the chip directly. Feel free to format very simple binary protocol to post 0xXXXXYYYY pair. You can also use something like "boundaries" to be sure that comming data are correctly alligned. I think, this thing would help you to make the data writing: https://stackoverflow.com/questions/27609972/open-a-serial-port-with-arduino-using-c-with-xcode-on-mac

By using of chipType, you should specify the 1 which is "OPL2". When you built OPL3-BE (with CONFIG+=oplproxy on QMake or -DENABLE_OPL3_PROXY=ON on CMake build) and when you'll build your liboplproxy.dylib, put it into OPL3BE.app/Content/MacOS folder, then, it should work.

Wohlstand avatar Aug 16 '19 23:08 Wohlstand

One note: if you are using C++ in your plugin, you should specify extern "C" to exported functions to make them ABI-compatible. Otherwise, just make your plugin code in pure C.

Wohlstand avatar Aug 16 '19 23:08 Wohlstand

Vitaly, I wish I can be that fluent in the app development. But I do afraid I will not be able even to compile your source under OS X due to so many external references to libraries. This simple Arduino sketch is taking those two byte values without a CRC or whatsoever protocol. https://github.com/DhrBaksteen/ArduinoOPL2/blob/master/examples/DosBoxPassthrough/DosBoxPassthrough.ino I highly appreciate your work and Maarten's OPL2 board (I'm not involved in this project development ), I just want to merge it together for other musicians. I need your help, please.

Deftaudio avatar Aug 17 '19 05:08 Deftaudio

Would you be able to test this feature on a Windows build? It's for a practical reason; we don't yet have an automatic Mac build. (but the result is going to be compatible with Mac)

jpcima avatar Aug 17 '19 08:08 jpcima

Hi all, I was trying to hack in serial communication through the win9x_opl_proxy to try this out. when @Deftaudio contacted me. Unfortunately I'm having no luck compiling the source so far.

It looks simple enough to 'translate' from OPL3 to OPL2 by simply ignoring unsupported registers / channels. That's what I intended to do in my Arduino code. Would be cool to see this work on my boards :)

DhrBaksteen avatar Aug 17 '19 08:08 DhrBaksteen

Hi @DhrBaksteen I've just examined a set of possibilities for implementing serial today. To go with QSerialPort (Qt5) seems a piece of cake, especially in that it also provides the discovery of hardware ports, and it will be nice to present it in a drop-down menu. My first thought was to implement it as another virtual chip choice inside the Bank Editor, rather than relying on the proxy, due to depending on Qt; and also avoiding to juggle with different variants of the proxy DLL.

jpcima avatar Aug 17 '19 09:08 jpcima

Ah that sounds great. I'm not familiar with Qt so for me it's a bit of a steap learning curve for now. If you have something that I can help out testing with or you need some info from me on the OPL2 board's code then I'd be happy to help.

DhrBaksteen avatar Aug 17 '19 10:08 DhrBaksteen

I work on it.

jpcima avatar Aug 17 '19 10:08 jpcima

Okay, I'll try to set up macOS automatical building. Anyway it's very easy to build: it needs Qt 5 only as a dependency.

Wohlstand avatar Aug 17 '19 10:08 Wohlstand

Need to test Windows build of PR #154 on the real hardware. (or build other platforms yourself)

see https://github.com/Wohlstand/OPL3BankEditor/pull/154#issuecomment-522232761

jpcima avatar Aug 17 '19 12:08 jpcima

@DhrBaksteen, I have a fix regarding the serial ready to test on hardware, at PR #155. I checked on the virtual serial port driver for Win7. Can you try?

jpcima avatar Aug 18 '19 08:08 jpcima

@jpcima It works perfectly now! See the video evidence of me trying a few instruments randomly.

I will go and add referals from the OPL2 library to this project and mention it on the Tindie page of the OPL2 board. This is a great addition that will be helpful to many people who just want to mess around with the board as a synth.

DhrBaksteen avatar Aug 18 '19 09:08 DhrBaksteen

It's perfect. I merged the working changeset to master. If you're going to advertise the program, then maybe it's an interesting time to release a version, even if a beta or rc. @Wohlstand what do you think?

jpcima avatar Aug 18 '19 09:08 jpcima

Cool! I think, yeah, a good idea! :fox_face: However, if no way to make the detection of OPL2 vs OPL3, can you make two serial port menu items to allow manual choice of OPL2 or OPL3. Anyway, it's easy to make a detection of OPL3 and OPL2, there are many old code samples around Internet, it will need also reading of result from the chip (no need to bind that, do this inside serial module only on every attempt to switch it). It's much easier to make a detection of OPL2 or OPL3 than making copy pasta as second menu item... I'll try to find some, and I will need a test...

Wohlstand avatar Aug 18 '19 09:08 Wohlstand

@Wohlstand, there is no choice possible of OPL2/OPL3 under this serial protocol, because it sends 2 byte pairs, and OPL3 is going to need a third.

I thought about proposing a drop-down menu which manually indicates a protocol, having ArduinoOPL2 in there. If the user selects, it's not needed to have such complication.

Anyway there's only one protocol known, I've not bothered to add it, but I can add it just for clarity.

jpcima avatar Aug 18 '19 09:08 jpcima

@Wohlstand, @jpcima would it help you if I implement a way to idintify the board?

The interface between the Arduino and the OPL2 does not implement reading back any of the registers or timer IRQ (the Arduino keeps a copy of the register values). So any of the tricks to detect the OPL2 that I know of will not work. But I could make the interface return a string, for exaple writing any value to register 0xFF could make the Arduino respond with 'ArduinoOPL2'. That would allow you to identify the board, allow for later epansion and you can make sure that the Arduino and OPL3BankEditor are in sync with sending their data.

DhrBaksteen avatar Aug 18 '19 12:08 DhrBaksteen

If there is another maker of serial interface in the future and its own protocol, I'd rather not deal with each modality of detection that exists in every case. Things should be simple.

Is something wrong about a configuration item? like pictured Capture du 2019-08-18 15-14-35

jpcima avatar Aug 18 '19 13:08 jpcima

Well it's done.. what remains is to offer a Mac build. @Wohlstand what about your PGE builds of Qt? Considering travis has a mac platform, maybe we're able to call macdeployqt and wrap it.

jpcima avatar Aug 23 '19 16:08 jpcima

Here are scripts running whole build, and here is a link to static Qt toolchain that I use: https://github.com/WohlSoft/PGE-Project/blob/master/.travis.yml https://github.com/WohlSoft/PGE-Project/tree/master/_common/travis-ci on Mac is better to use static Qt toolchain, otherwise, shared Qt after macdeployqt results heavy package :thinking:

Wohlstand avatar Aug 23 '19 16:08 Wohlstand

Thanks for reminding, will try to make the build once I'll be able...

Wohlstand avatar Aug 23 '19 16:08 Wohlstand

Thank you everyone, I downloaded this patch. Installed QT Creator with latest QT on OS X. Compiled it just fine with basic settings, but want to move it to other system for the first test, so tried to compile it with static flag and failed. The only extra flag is QMAKE_LFLAGS+=-static

and that's the error: library not found for -lcrt0.o Can you suggest, what am I missing?

Deftaudio avatar Aug 24 '19 02:08 Deftaudio

For static Qt you should compile Qt itself. However, with shared build, you have to use macdeployqt tool which will automatically pack bundle with all necessary frameworks and dylibs.

Wohlstand avatar Aug 24 '19 05:08 Wohlstand

Anyway, you can just take this toolchain http://wohlsoft.ru/docs/Software/QtBuilds/qt-5-12-4-static-macosx-10-14-5.tar.bz2 and unpack it into /Users/StaticQt/ (create the folder by root user and chown it to yourself). To build by it, use it's QMake.

Wohlstand avatar Aug 24 '19 05:08 Wohlstand

Thank you Vitaly, I installed that toolchain per your recommendation, but it gives me other error now: :-1: error: Unknown module(s) in QT: serialport Seems it's missing some library that newer QT has.

Deftaudio avatar Aug 25 '19 05:08 Deftaudio

I find Qt SerialPort has its own repo, and is able to be built on its own. Maybe we can have it this way without rebuilding the whole of Qt. https://wiki.qt.io/Qt_Serial_Port

jpcima avatar Aug 25 '19 10:08 jpcima