How to use other language code in Delphi?

634 Views Asked by At

I am interested in integrating language from another audio programming language (ChucK) into my Delphi project. I know that maybe that is possible with dynamic-link libraries (.DLLs) but I am not familiar with this.

Does anyone know how I can configure a project to get the two languages working together?

2

There are 2 best solutions below

0
On

A quick glance at the ChucK documentation suggests three possible approaches, all arising from the fact that ChucK is both a language and also a virtual machine (VM) to run the programs written in that language.

ChucK is open source, so the full source code of that VM is available but is written in C++. ChucK is available either in this source code form or as a ready-to-run executable for the supported platforms.

I could find no reference to any DLL version of the VM for use within other programs. Which isn't to say that such a DLL has not been developed by others, only that I couldn't find any reference to one and it does not appear to be part of the standard distribution of ChucK itself.

I did find some source code which references a DLL in the context of ChucK but it was not entirely clear to me whether this was a DLL API for using ChucK or part of the implementation, allowing ChucK itself to be modularised or extended via DLL's.

The three options I see before you are:

  1. Port the Chuck VM to Delphi. That is, translate all of the ChucK VM source code to Delphi. This will give you a version of ChucK implemented entirely in Delphi which is capable of running ChucK programs.

  2. Implement a DLL API (possibly based around or starting from that link above) for the existing ChucK VM source code in C++ in a way that enables you run ChucK programs by calling into that DLL to be run by the existing C++ implementation of ChucK.

  3. Run ChucK programs using the ChucK exe using ShellExecute(), WinExec() or CreateProcess() etc, just as you would if you wished to run any other external program from a Delphi program.

These are presented roughly in descending order of difficulty. That is, a full port to Delphi (Opt 1) is likely to be beyond your capability.

Implementing a DLL interface around the existing C++ code (Opt 2) may be possible depending on your C++ and Windows development skills.

Calling an external program (Opt 3) is relatively straightforward.

Which approach is right for you depends on the nature of your assignment, the objectives, and your confidence/skills in the areas involved.

Good luck.

0
On

An easy way to get different systems talking to each other is use Open Sound Control (OSC). ChucK has OSC receivers and senders (search for "> OSC") built into it and Delphi looks like it implements OSC as well.

OSC works over networks but you can also just send messages to your own local machine (localhost). The ChucK examples do this referenced above do this.

It's not a tight integration but it'll get the Delphi-ChucK relationship going.