hosting dssi plugins

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

hosting dssi plugins

Post by skei »

i know dssi is more or less dead, superseded by lv2.. but i like to take things step by step, and there's a few dssi plugins i'd like to be able to use in a vst-only host.. lv2 is next, after ladspa and dssi..
so, here we go..

after getting a ladspa (to vst) wrapper working, i wanted to add dssi support too.. it was/is pretty simple, as dssi is more or less 'just' a ladspa plugin with some additional functionality for passing in (midi) events, and handling presets (programs).. at the moment, i totally ignore the gui aspect.. so.. my wrapper seems to be working as espected, except for one thing - i can't get any sound out of it!

i load the .so file, find the 'dssi_descriptor' function, and call it to get the descriptor.. from this dssi descriptor i find the ladspa descriptor, which i use for the basic things like instantiating and activating the plugin, just like i would normally do with a ladspa plugin.. then, i prepare some midi events. and pass these to the plugin when i call run_synth().. but no sound is coming out of the plugin... and i don't know where to start hunting for errors/bugs.. i don't know if it is because i haven't initialized/setup the plugin properly, of if my midi events are illformed, or whatever..

i have checked if the pointers in the ladspa and dssi descriptors are not NULL, and i send events like this (removed a lot of code in an effort to make it more understandable):

in my (vst) plugin class, i have

Code: Select all

uint32          MNumMidiEvents;
snd_seq_event_t MMidiEvents[S3_DSSI_MAX_MIDI_EVENTS];
which are reset/zeroed when instantiatinf the plugin..
then, when my vst plugin receives a midi event, i do something like this:

Code: Select all

if (MNumMidiEvents < S3_DSSI_MAX_MIDI_EVENTS) {
  uint32 chan = AMsg1 & 0x0f;
  uint32 msg  = AMsg1 & 0xf0;
  switch(msg) {
    case 0x80: // note off
      MMidiEvents[MNumMidiEvents].type                = SND_SEQ_EVENT_NOTEOFF;
      MMidiEvents[MNumMidiEvents].time.tick           = AOffset;
      MMidiEvents[MNumMidiEvents].data.note.channel   = chan;
      MMidiEvents[MNumMidiEvents].data.note.note      = AMsg2;
      MMidiEvents[MNumMidiEvents].data.note.velocity  = AMsg3;
      break;
    case...
      ...
  }
  MNumMidiEvents++;
}
and, finally, when the vst plugin is called to produce a block of audio, i call run_synth:

Code: Select all

MDssiDescriptor->run_synth(MLadspaHandle,ANumSamples,MMidiEvents,MNumMidiEvents);
MNumMidiEvents = 0;
but this results in no sound..

does anybody know of a simple example dssi host? the more minimal, the better.. no gui or osc stuff.. just loading the plugin, instantiating and activating it, sending a few midi events through it, and capturing or playing the resulting audio? or even better, a simplistic dssi plugin that just prints out some info..

- tor-helge

if i ever get the dssi hosting sorted out, i plan to take the next step, and look at lv2.. then, if that works, i could potentially look at the gui mess..
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: hosting dssi plugins

Post by j_e_f_f_g »

No, don't send midi bytes in ALSA's "sequencer format". Send raw midi bytes. For example, a middle C note-on (on channel 0), with a max velocity of 127, would be the following three bytes:

Code: Select all

unsigned char * MMidiEvents;

case 0x90: // note off
      MMidiEvents[0] = 0x90;
      MMidiEvents[1] = 64;
      MMidiEvents[2] = 127;
      MMidiEvents += 3;
      break;

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

aahh..
thanks a lot!
will try that immediately!
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: hosting dssi plugins

Post by j_e_f_f_g »

Oh wait. I was thinking of VST. DSSI does use ALSA sequencer format. Must be something in the way you're initializing that ALSA struct. Are you sure you're calculating the "tick time" correctly?

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

yeah.. i just saw that the run_synth expects a ptr to an array of snd_seq_event_t.. :-)

actually, i don't calculate the tick time at all..
in the dssi.h file i see:
"Each event is timestamped relative to the start of the block, (mis)using the ALSA "tick time" field as a frame count. The host is responsible for ensuring that events with differing timestamps are already ordered by time." - and i receive these midi events (with the offset) from the vst host, so i just stuff it into the snd_seq_event_t struct/array...

at the moment i initialize the plugin exactly similar to how i initialize ladspa plugins.. but i will look more into it..
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: hosting dssi plugins

Post by j_e_f_f_g »

You're setting the time field to 0 then, right?

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

no, i didn't..
i interpreted the time tick to be measured in samples, from the start of the current block of samples to process.. the offset i receive from the vst host is exactly this, so i expected it to "just work"..
but i just tried to set it to 0.. no difference..
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: hosting dssi plugins

Post by j_e_f_f_g »

Attached to this post is source to a "dssi_test" plugin I threw together for you. It simply tests that the values you're passing it are correct, and displays progress messages (to the terminal window). For example, it will print a message when you call its run_synth(), check your passed values and report its findings (good or bad), and tell you whenever you successfully turn a note on or off.

I compiled a 64-bit version for you. Run your host from a terminal window.
Attachments
dssi_test.zip
(6.19 KiB) Downloaded 62 times

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

that's awesome!
thanks a lot!
it will make things a lot easier!

- tor-helge
User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

first of all, thanks a lot for this debug/test dssi plugin!

bitwig studio deactivcates (hides) stdout for some reason, so i tried to modify it a little to send output through a socket (like i do for debugging my own plugins in bitwig).. but there's some stuff in my plugin framework i have to fix before i can just simply compile stuff that's not meant for the framework.. for example, it tries to do some trickery with exported symbols and stuff depending on some #defines.. and i haven't set up anything for compiling dssi plugins :-/ so i tried jost instead.. the plugin prints out a lot of stuff.. and it seems like it receives midi events and everything! haven't really dived into the details yet.. will do later tonight..

but i saw that it said something like "called with the wrong descriptor" during instantiation.. i checked the dssi_test.c sources..

Code: Select all

if (chk_descriptor(descriptor)) printf("correct");
else printf("wrong");
the chk_description function:

Code: Select all

static int chk_descriptor(const void * descriptor) {
  if (descriptor == &DssiDescriptor) return 1;
  return 0;
}
but, in dssi.h i see:
"In order to instantiate a synth the host calls the LADSPA instantiate function, passing in this LADSPA_Descriptor pointer."
does this mean that your chk_descriptor function is wrong? shouldn't it check for descriptor == &LadDescriptor, or have i misunderstood?

- tor-helge
User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

update:

here's the complete output from a quick run with jost loading my dssi_wrapper vst-plugin, which loads your dssi_test plugin..
a couple of things to note:

* the output is a mixture of jost output, some of my own debug output, and your plugin's output, so it's a bit messy..

* i commented out some printf stuff from your plugin, as it was flooding the terminal.. mainly connect_port and run_synth (i just print out some midi stuff when there's any incoming midi events).. from earlier tests, before i commented out the lines, i saw them being called properly (at least i think so)..

* looks like jost doesn't call effClose when deleting a vst plugin, so my wrapper isn't told to delete itself, and i get a memory leak (see the bottom 'memtrace' part).. jost is full of other bugs too, so i don't care much about that at the moment.. :-)

* in the beginning, when calling instantiate(), your dssi_test says "Host has passed the wrong descriptor", but i think you're chk_descriptor function is wrong? it checks if the descriptor passed in is the DSSI_Descriptor, while instantiate() want a Ladspa_Descriptor..

ok, i'll put this on hold for a while now, while i'm doing what i should have been doing today instead.. :-)
i'll continue when i'm back home later tonight..

- tor-helge


Code: Select all

skei@cernobyl ~ $ jost
 
Plugin In loaded OK 
Plugin Out loaded OK
 
S3_Dssi::load /DATA/code/s3/bin/dssi_wrapper/dssi_test.so
S3_Dssi::initDescriptor 0
S3_Ladspa::initPorts
S3_Ladspa::instantiate samplerate:44100

=============================
Host is calling plugin's instantiate()...
Host has passed the wrong descriptor.
Host has passed a sample rate of 44100.
The plugin handle has been successfully allocated.
Plugin's instantiate() has finished and is returning to the host...
=============================

DSSI_Descriptor:
  api version:                     1
  ladspa descriptor:               0xb8d01d60
  configure():                     0x00000000
  get_program():                   0x00000000
  select_program():                0x00000000
  get_midi_controller_for_port():  0xb8b009f0
  run_synth():                     0xb8b00a98
  run_synth_adding():              0x00000000
  run_multiple_synths():           0x00000000
  run_multiple_synths_adding():    0x00000000

LADSPA_Descriptor:
  name:                 'Dssi Test'
  label:                'DssiTest'
  maker:                'Jeff Glatt'
  copyright:            'GPL3'
  unique id:             666
  num ports:             2
  flags:                 0x00000004
  instantiate():         0xb8b00c9e
  connect_port():        0xb8b00c09
  activate():            0xb8b00a72
  run():                 0xb8b00bf1
  run_adding():          0x00000000
  set_run_adding_gain(): 0x00000000
  deactivate():          0x00000000
  cleanup():             0xb8b00c3c

S3_Ladspa::activate

=============================
Host is calling plugin's activate()...
Host has passed a good plugin handle.
Plugin's activate() has finished and is returning to the host...
=============================

Plugin Dssi Test loaded OK 

[s3_dssi.h:midiEvent:139] midi.. offset 0 : 144 48 76
midi events: 1
Midi note 48 is turned ON.
[s3_dssi.h:midiEvent:139] midi.. offset 0 : 128 48 73
midi events: 1
Midi note 48 is turned off.

S3_Ladspa::deactivate
S3_Ladspa::cleanup

=============================
Host is calling plugin's cleanup()...
Host has passed a good plugin handle.
Attempting to free the plugin handle...
The plugin handle has been successfully freed.
Plugin's cleanup() has finished and is returning to the host...
=============================

----------------------------------------
memtrace
----------------------------------------
* num alloc     10
* num free      9
* num leaks     1
* max allocated 581405
* leaked memory 572760
----------------------------------------

* [dssi_wrapper.h:main_plugin:289] new,0xc323f010,572760
----------------------------------------
User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

last update for a while, i promise :-)
i finally got whysynth more or less working with the wrapper in bitwig studio now!!
i noticed i had to go through a weird deactivate/active (suspend/resume in vst-land) to make it work..
but now i know where to investigate further!
Luc
Established Member
Posts: 741
Joined: Fri Mar 27, 2015 1:04 pm
Been thanked: 1 time

Re: hosting dssi plugins

Post by Luc »

This is exciting! :o
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: hosting dssi plugins

Post by sadko4u »

Good job! Following your work!
LSP (Linux Studio Plugins) Developer and Maintainer.
User avatar
skei
Established Member
Posts: 337
Joined: Sun May 18, 2014 4:24 pm
Has thanked: 8 times
Been thanked: 57 times
Contact:

Re: hosting dssi plugins

Post by skei »

just noted that i had forgotten to let you know that the dssi wrapper is more or less working as i want now.. but since it doesn't do any gui stuff, some of the wrapped plugins are close to useless.. i have had very good success with whysynth as i mentioned earlier, and can browse through the included presets, and tweak the parameters.. and it uses very little cpu, it seems! nice :-)
hexter and horgand also works, but without a gui, you can'ẗ tweak the sound much.. you can browse the presets, though :-)

i thought about diving into the gui issue, but after looking at how it works, i decided to stay far away from that!! in my (personal) opinion, it's a complete mess!! which also means that there's little chance to do a similar wrapper for lv2.. :?

now i will let this rest a little, while i focus on 'hardening' my plugin framework, add back cairo graphics support (code is finished and working, just not properly merged into the framework), and finish a few of my own vst plugins, before making it all public..
Post Reply