x42 / tuna.lv2

Musical Instrument Tuner
http://x42-plugins.com/x42/x42-tuner
GNU General Public License v2.0
26 stars 8 forks source link

MIDI output #10

Closed matthewjumpsoffbuildings closed 5 years ago

matthewjumpsoffbuildings commented 5 years ago

Is there any chance you would consider adding MIDI out of the detected note and how many cents its off being in tune, as Note On and Pitch Bend values?

x42 commented 5 years ago

An earlier version had that feature.

It was more trouble than it's worth. The timing of the events is all over the place and users expected it to be an "audio to midi" tool.

Are you planning to use this for an external display?

matthewjumpsoffbuildings commented 5 years ago

yes, im going to send it to a midi foot controllers LED display

re the timing, wouldnt it be simple enough to just send the note-on on initial detection, then send the pitch bend values out at a fixed rate? like once every n ms, until detection cant hear a note anymore, then send a note-off?

matthewjumpsoffbuildings commented 5 years ago

oh i should have said, the n ms for pitch bend out is not time critical, anything faster than 25-30 times a second is visually smooth enough for most people

also, ideally for sending out how many cents off the note is, id actually prefer something other than pitch bend, eg perhaps use 1 CC number to send values from 0-100 for how sharp it is, and another CC to send 0-100 for how flat it is, and if both CCs send 0 its in tune? that part im not sure about but ive been playing around with parsing pitch bend for the external display and its 8000 odd potential values are just a pointless step since we only really care values from 0-100...

x42 commented 5 years ago

It's perfectly fine for visualization. ~25fps, also allows to get a full 25Hz cycle to accurately allow tuning of bass guitar's fundamental.

In short: If you increase timing-precision, you loose frequency resolution. Tuna focuses on the latter, which is why it's not very useful for low-latency audio-to-midi.

Anyway, I'm leaning towards following MIDI standard whenever possible. The problem is that pitch-bend range is left undefined.

The best would be to send a MIDI Tuning Standard (MTS) message -- https://en.wikipedia.org/wiki/MIDI_tuning_standard

A realtime SysEx message with well defined units:

F0 7F 7F 08 02 00 01 kk xx yy zz F7

kk = Note number to tune xx = semitone (MIDI note number to re-tune to) - here always the same as kk. yy = MSB of fractional part (1/128 semitone = 100/128 cents = .78125 cent units) zz = LSB of fractional part (1/16384 semitone = 100/16384 cents = .0061 cent units)

That'll also allow to re-tune synth-plugins to actual 'detuned' real instruments (and prevent casual musicians to use it as audio-to-midi tool).

Now the big question: Can your controller parse those?

matthewjumpsoffbuildings commented 5 years ago

ye i have written a simple MIDI effect that would sit in between the tuner and the MIDI output to the device, should be able to parse that fine

question - if yy value is 127, does that mean its 100 cents too sharp or too flat from kk?

x42 commented 5 years ago

oops. I was wrong above with "here always the same as kk" . cents is always positive.

So if a you were tuning the A-string 220Hz and it would currently be 215 Hz: -39.80 cent. The report would be G# (note 68) + 60.20 cent

60.20 (2^14 - 1) / 100 = 9862 = 77 128 + 6

kk = 69 xx = 68 yy = 77 zz = 6

hmm. that's not great. I'll sleep over it.

x42 commented 5 years ago

If you've written a middle-man software already, can't that just use the plugin's output parameters instead of MIDI?

matthewjumpsoffbuildings commented 5 years ago

OK i feel like an idiot, I just discovered this plugin and hadnt tested it yet, then went to download it and realised my DAW (Reaper on Windows 7 64 bit) doesnt support it :/

I still think its a handy feature tho :)

x42 commented 5 years ago

Heh, no problem.

Except it can be made to work in Reaper (on any platform) with https://github.com/x42/lv2vst

Actually Reaper may add support for the LV2 as plugin standard. There was apparently already prototype for it (and that first iteration was rejected in first iteration because LV2 doesn't support switching sample-rates).

Still for Reaper, you'll probably be better off using a ReaScript directly

matthewjumpsoffbuildings commented 5 years ago

is there a compiled windows version of lv2vst? im not the greatest at compiling from source

theoretically are you saying that if i can get tuna.lv2 working in Reaper, i can check the values of some parameters and that will tell me what note and how many cents off it is?

x42 commented 5 years ago

https://x42-plugins.com/tmp/x42_tuner_vst.w64.exe Installs a VST2 plugin in C:\Program Files\Common Files\VST\x42\ It should show up in Reaper as "x42 Instrument Tuner" audio-in, audio-out (passthru) and midi-out.

matthewjumpsoffbuildings commented 5 years ago

odd, i installed it, ensured my VST settins in reaper were scanning C:\Program Files\Common Files\VST, and rescanned for new plugins, and its not showing anything new?

x42 commented 5 years ago

I just did a quick check Reaper/Win7 64bit and the plugin loads, I don't know Reaper enough to test MIDI SysEx output though.

reaper-x42-tuner

matthewjumpsoffbuildings commented 5 years ago

If you put a ReaControlMIDI after it and open the Log panel you should see if the Sysex is being output.

I wonder why its not showing up for me, I ran the installer and added C:\Program Files\Common Files\VST to my Reaper VST scan folders, am I missing something? A license key or something perhaps?

x42 commented 5 years ago

No license key need. Here "Reaper (x64)" just picked it up. I'm using the Reaper demo/evaluation license to test. Are you perhaps using 32bit Reaper on 64bit windows?

Thanks for suggesting ReaControlMIDI. That helped. Now that I managed to get it going, I found a bug with SysEx events in the VST wrapper. Please re-download + re-install https://x42-plugins.com/tmp/x42_tuner_vst.w64.exe

Works now:

rea-midi-dump

matthewjumpsoffbuildings commented 5 years ago

Ok i have it working! It seemed unless I added C:\Program Files\Common Files\VST\x42 to reapers scan paths (and not just C:\Program Files\Common Files\VST), reaper didnt scan subdirs... weird

Im seeing the sysex messages, now i can parse them and it should work great, thanks so much!

matthewjumpsoffbuildings commented 5 years ago

OK im testing it out, first question is its sending out 12 bytes of data per message, but the first 8 bytes or so seem to be the same regardless of what note im trying to tune? What are the first bunch of bytes for?

Second question, bytes 8 and 9 seem to contain the MIDI note of the string im trying to tune, would that be kk and xx in your previous comment?

Also, byte 10 seems to be the cents value, would that be correct? Eg yy from your previous comment... And to get that value back to cents I can just times it by 0.78125?

matthewjumpsoffbuildings commented 5 years ago

this seems to be correct

sys_kk = buf[7];
sys_xx = buf[8];
sys_yy = buf[9] * 0.78125;
sys_kk > sys_xx ? ( sys_yy = -(sys_yy-100); );

sys_kk will contain the correct note, and sys_yy will contain the cents, negative or positive, from that note

x42 commented 5 years ago

Yay! Great that you've manage to make it work. As for SysEx message, you're spot in. Compare to how it's generated:

https://github.com/x42/tuna.lv2/blob/656ea6ed8cf0e06285558b30114681e00ccd34e8/src/tuna.c#L563-L566

bytes 9 and 10 are two parts of a 14bit value: 100.0 * (buf[9] << 7) | buf[10]) / 16383.0) cent, but buf[9] * 0.78125; is close enough.

Currently there is one message sent per process cycle, I'm planning to rate-limit it. Only send a change if the difference to the last message is > 0.02 cent (or something)

matthewjumpsoffbuildings commented 5 years ago

ye i ended up only spitting out a value every few buffers (im running for live use at 64 samples buffer). the realtime performance of the LV2 -> VST2 wrapper is not bad, my longest block time hovers around 0.2ms (at current sample rate i have 1.4ms block time), so i could probably run the 3 i need (2 guitars 1 bass). im guessing performance is even better with native LV2 ye? fingers crossed reaper adds LV2 support at some point...

however i am getting a weird crash - if i have an instance of tuna open on a record armed track in reaper with monitoring enabled, and the input guitar cable is touched, which creates a loud pop/buzz noise, Reaper crashes immediately :(

matthewjumpsoffbuildings commented 5 years ago

oh i see commit 9438e3e25ea37de2c0ba5a9f88fbee492b6a15a1 adds rate limiting on the midi output, does https://x42-plugins.com/tmp/x42_tuner_vst.w64.exe include this update?

x42 commented 5 years ago

I have not been able to reproduce or track down the crash in Reaper yet.. that's mysterious.

And no, I have not updated the VST, yet. last-modified: "Wed, 31 Jul 2019 03:36:10 GMT". Do you think the crash is due to the missing rate-limit?

matthewjumpsoffbuildings commented 5 years ago

ye that is weird, im not sure if it has anything to do with the rate-limit. if it helps im running reaper at 64 samples buffer size on an i7 4790 CPU, using an RME RayDAT PCIe audio card.

if its not too hard to make another vst that would be awesome, id love to test out the rate limited version and see if that triggers the crash

x42 commented 5 years ago

I need to start properly version it, and had postponed that until v5.. -- meanwhile there's no a 4.14-4 build at the same url :(

https://x42-plugins.com/tmp/x42_tuner_vst.w64.exe
Sun, 18 Aug 2019 20:41:09 GMT md5sum: ff7593e1f13ebcdccd0886ee7431ebb0

matthewjumpsoffbuildings commented 5 years ago

ok i just tested the updated version and it seems to have fixed that bug with reaper crashing when i touch the input lead and create a pop/buzz

x42 commented 5 years ago

Thanks for testing. Interesting to know that the crash is gone, even though I don't have a good explanation as to why or why it was there in the first place.

x42 commented 5 years ago

https://x42-plugins.com/tmp/x42_tuner_vst.w64-v0.5.0.exe