Wohlstand / OPL3BankEditor

A small cross-platform editor of the OPL3 FM banks of different formats (Downloads in README below)
GNU General Public License v3.0
143 stars 12 forks source link

OPL2 hardware unit connectivity #153

Closed Deftaudio closed 11 months ago

Deftaudio commented 5 years ago

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.

jpcima commented 5 years ago

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.

Deftaudio commented 5 years ago

Hi JB, that sounds fantastic, thank you.

Wohlstand commented 5 years ago

@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 commented 5 years ago

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).

Deftaudio commented 5 years ago

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?

Wohlstand commented 5 years ago

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 commented 5 years ago

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.

Deftaudio commented 5 years ago

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.

jpcima commented 5 years ago

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)

DhrBaksteen commented 5 years ago

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 :)

jpcima commented 5 years ago

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.

DhrBaksteen commented 5 years ago

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.

jpcima commented 5 years ago

I work on it.

Wohlstand commented 5 years ago

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.

jpcima commented 5 years ago

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 commented 5 years ago

@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?

DhrBaksteen commented 5 years ago

@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.

jpcima commented 5 years ago

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?

Wohlstand commented 5 years ago

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...

jpcima commented 5 years ago

@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.

DhrBaksteen commented 5 years ago

@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.

jpcima commented 5 years ago

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 commented 5 years ago

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.

Wohlstand commented 5 years ago

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 commented 5 years ago

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

Deftaudio commented 5 years ago

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?

Wohlstand commented 5 years ago

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 commented 5 years ago

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.

Deftaudio commented 5 years ago

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.

jpcima commented 5 years ago

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

Wohlstand commented 5 years ago

@Deftaudio , damn, I forgot that I disabled that part... Anyway, if you are using shared Qt, please run macdeployqt to add everything. So, about my static build, looks like I should enable SerialPort thing...

jpcima commented 5 years ago

@Deftaudio, there exists an experimental Mac build since we added it today, it's linked on the main page README.

Deftaudio commented 5 years ago

Would you also please build it in 32bit to get it working from 10.7 and above? Thank you.

Wohlstand commented 5 years ago

10.7? This will also require building of older Qt toolchain as this one is incompatible with older than Sierra (previous Qt version required El Capitan for work)

Deftaudio commented 5 years ago

Yes, I meant 10.7 to utilize low end macs for that :)

Wohlstand commented 5 years ago

Okay, looks like I should compile Qt 5.5 to support 10.7: https://wiki.qt.io/PlatformSupport

Wohlstand commented 11 months ago

I think, I can close this as all works was done a while ago.