Old 05-03-2015, 12:47 PM   #1
syntetic
Human being with feelings
 
syntetic's Avatar
 
Join Date: May 2014
Posts: 160
Default Reset pitch cc data to default.

Prompt, please how to reset selected pitch cc data to the center by a script; python, eel, lua no matter.
I can`t set pitch precisely on the center, 63 & 64 put pitch above and below.

Code:
function set_cc_value()
(
  (act_editor = MIDIEditor_GetActive()) ? (
    (take = MIDIEditor_GetTake(act_editor)) ? (
      event_count = MIDI_CountEvts(take, notecntOut, ccevtcntOut, textsyxevtcntOut);
      i = 0;
      loop (ccevtcntOut,
        MIDI_GetCC(take, i, sel, mute, ppqposOut, chanmsgOut, chanOut, msg2Out, msg3Out);
        sel == 1 ? (
          MIDI_SetCC(take, i, sel, mute, ppqposOut, chanmsgOut, chanOut, msg2Out, 127, 1);
        ); //end if sel
        i += 1;
      ); // end loop
      MIDI_Sort(take);
    ); // end if take    
  ); // end if act editor
); // end func
set_cc_value(0);

Last edited by syntetic; 05-03-2015 at 01:22 PM.
syntetic is offline   Reply With Quote
Old 05-03-2015, 01:25 PM   #2
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Fwiw: pitch bend events are NOT CC events.

Moreover, pitch bend has (per the MIDI specs) a 14-bit resolution, and the center point (i.e. reset, no pitch bend) is shown visually as 0, while its actual value is 8192 (the 14-bit range from to 16383 is shifted to -8192 to +8191).
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-03-2015, 01:52 PM   #3
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Nevertheless in ReaScript pitch is set with MIDI_SetCC. And you deal with two 7bit values (0 to 127) which together make for the 14bit resolution, so you're almost there. MSB (most significant byte) makes for your ordinary 128 steps you are used to and LSB (least significant byte) does adittional 128 steps between each of the MSB steps (which also means that if you leave LSB at zero at all times, you deal with the ordinary 128 steps, which makes 14bit downward compatible to 7bit MIDI).

The error is that you forgot to set the LSB to 0, so that MSB=64 will be a bit off center still (MSB and LSB "add" up to a bit more than 8192), if the event you're getting has an lsb other than zero.


For pitch, concerning MIDI_SetCC, the MSB is set with msg3in (which you did) and the LSB with msg2in.

if you change your script here:
Code:
MIDI_SetCC(take, i, sel, mute, ppqposOut, chanmsgOut, chanOut, 0, 64, 1);
then the lsb is set to zero and msb 64 hits the center just fine.

Last edited by gofer; 05-03-2015 at 02:05 PM.
gofer is offline   Reply With Quote
Old 05-03-2015, 02:05 PM   #4
syntetic
Human being with feelings
 
syntetic's Avatar
 
Join Date: May 2014
Posts: 160
Default

Thanks!!!
syntetic is offline   Reply With Quote
Old 05-03-2015, 02:08 PM   #5
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by gofer View Post
Nevertheless in ReaScript pitch is set with MIDI_SetCC.
That's very odd, and quite misleading - I would never have deduced that from the ReaScript API documentation. But hey, good to know.

So how is that function supposed to know that it should use pitch bend rather than CC events - perhaps by setting chanmsgOut to some specific value?
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-03-2015, 02:42 PM   #6
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Banned View Post
That's very odd, and quite misleading - I would never have deduced that from the ReaScript API documentation. But hey, good to know.

So how is that function supposed to know that it should use pitch bend rather than CC events - perhaps by setting chanmsgOut to some specific value?

This code snippet is from the MIDI velocity tool (Breeder made this bit IIRC):
Code:
.
.
.

    // Pitch
    ) : lane_type == 3 ? (
      while ((index = MIDI_EnumSelCC(take, index)) != -1) (
        MIDI_GetCC(take, index, selectedOut, mutedOut, startppqpos, chanmsgOut, chanOut, msg2Out, event_value);
        chanmsgOut == 0xE0 ? (
          event_list[i] = index;
          event_list[i + 1] = event_value;
          event_list[i + 2] = startppqpos;
          event_list[i + 4] = msg2Out;
          i += 5;
          sel_event_count += 1;
          event_value_sum += event_value << 7 | msg2Out;
        );
      );
.
.
.
spk77 is offline   Reply With Quote
Old 05-03-2015, 02:55 PM   #7
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

I think anything that's in CC lanes, apart from Velocity, Off velocity, SysEx and MIDI meta (text) can be done via MIDI_Get(Set)CC (or the more global MIDI_Get(Set)Evts, iirc). You're on the right track with chanmsgOut. The value for pitch would be 224.

To make sure that his script does only ever reset pitch events, there will need to be a test whether MIDI_GetCC returns 224 as chanmsgout, and only then MIDI_SetCC should come into play.
(EDIT: spk shows how in that snippet. hex 0xE0 = decimal 224)

A more versatile script would maybe get the last clicked lane and then act accordingly (as you can imagine, different methods are needed to reset/work on different message types).

I really wonder where the description of all this is, did we really reverse engineer all that stuff back then?

While I have a script running which gives me the numbers, I might as well list them:
- all ordinary CC give you 176 (actual number is msg2 out) (0xB0)
- pitch 224 (0xE0)
- PC 192 (0xC0)
- Channel Pressure 208 (0xD0)

Last edited by gofer; 05-03-2015 at 03:08 PM.
gofer is offline   Reply With Quote
Old 05-03-2015, 04:16 PM   #8
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Those numbers are simply the MIDI specs.

Imho that function should simply not be named after CCs if it handles other MIDI event types as well. MIDI_GetEvts makes way more sense. I'd just use that one for pitch bend to avoid adding to the confusion.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-04-2015, 12:27 AM   #9
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Ha! now that you say it But not quite, these numbers don't use the second digit (err, hexit? how'd that be called?) for channel number, it's always 0.

You can use MIDI_GetEvt, but it also gets all notes, so you might introduce redundant calls, depending on what you want to do. In the end it's just a bloody name and I wouldn't know a better one. As long as Cockos don't want to introduce an extra function for these "not CC, but similar" messages, I can live with it. But it should definitely be talked about on the API page.

Same not-quite-according-to-spec naming convention is valid for the other MIDI API functions as EnumSelCC, DeleteCC, InsertCC and in the description of Count_Evts (with the argument called ccevtcntOut), so at least they are kind of consequent there
gofer is offline   Reply With Quote
Old 05-04-2015, 05:31 AM   #10
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by gofer View Post
Ha! now that you say it But not quite, these numbers don't use the second digit (err, hexit? how'd that be called?) for channel number, it's always 0.
I assume you simply set the channel number using chanOut - the event type and channel numbers have apparently simply been split up for convenience, and are added automatically (which makes sense).
Quote:
Originally Posted by gofer View Post
You can use MIDI_GetEvt, but it also gets all notes, so you might introduce redundant calls, depending on what you want to do. In the end it's just a bloody name and I wouldn't know a better one. As long as Cockos don't want to introduce an extra function for these "not CC, but similar" messages, I can live with it. But it should definitely be talked about on the API page.
Yeah, I see the problem there. But the thing is, technically speaking, MIDI notes are even more similar to CCs as pitch bend events.

And it's quite silly to have a function explicitly named after a specific event type (CCs) that still requires the user to specify that he actually wants to use that specific type of events (using chanmsgOut = 0xB0), rather than pitch bend or aftertouch events. Imho Cockos has simply been very lazy and sloppy here, and the lack of proper documentation only adds insult to injury - so now it's much harder for the user to understand and slightly harder to actually use.

I haven't tested this yet, but what happens if you use MIDI_GetCC/MIDI_SetCC with chanmsgOut = 0x90? Does it get/set notes?
Quote:
Originally Posted by gofer View Post
Same not-quite-according-to-spec naming convention is valid for the other MIDI API functions as EnumSelCC, DeleteCC, InsertCC and in the description of Count_Evts (with the argument called ccevtcntOut), so at least they are kind of consequent there
It's consistently confusing and poorly documented, indeed.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-04-2015, 09:39 AM   #11
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Technically speaking they are all just some 3 byte messages. I don't follow you there, if they had thrown notes and CC together in the functions they split off the event functions instead of pitch and CC, you'd see me doubting Cockos' sanity .

I don't quite see the drama, apart from semantics. Of course you are right, strictly speaking. But on the other hand, the lanes are talked about as CC lanes all over the place (actions/menus/user guide, forum posts) and rarely if ever someone complained that there's velocity, pitch, channel pressure etc as well, so they should rather be called... yeah what... conglomerated MIDI message lanes or something. Sloppy, of course but does it really hurt?

I was extremely happy when they split out the functions to adress notes/"CC"/SysEx(andMeta) separately. Can't say I cared much about the name for "lane stuff but not all of it".

Documentation could be waaay better, I certainly agree with that.
gofer is offline   Reply With Quote
Old 05-04-2015, 10:43 AM   #12
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by gofer View Post
Technically speaking they are all just some 3 byte messages. I don't follow you there, if they had thrown notes and CC together in the functions they split off the event functions instead of pitch and CC, you'd see me doubting Cockos' sanity .
Well, notes and CCs are more similar in the sense that both notes and CCs require two 7-bit values, while pitch bend requires one 14-bit value.
Quote:
Originally Posted by gofer View Post
I don't quite see the drama, apart from semantics.
It's not a big drama, but semantics are important for naming API functions.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Old 05-04-2015, 01:15 PM   #13
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

I see that differently
Notes require 2 messages of 3 7bit values (you need note on and note off if used for musical purpose), whereas CC and pitch require a single message of 3 7bit values to be meaningful (without "running status"). Makes CC and pitch more similar to me, as does the actual use as "continuous" modifiers for parameters, whereas notes are more like something I switch on/off (this thought obviously doesn't fit so well for program change... or bank select on the CC message side, and some others too, but it's the most common use for CC, I think).
But this can't be the heart of the discussion, can it?

Which name would you prefer?

Last edited by gofer; 05-04-2015 at 01:21 PM.
gofer is offline   Reply With Quote
Old 05-04-2015, 04:34 PM   #14
Banned
Human being with feelings
 
Banned's Avatar
 
Join Date: Mar 2008
Location: Unwired (probably in the proximity of Amsterdam)
Posts: 4,868
Default

Quote:
Originally Posted by gofer View Post
I see that differently
Notes require 2 messages of 3 7bit values (you need note on and note off if used for musical purpose), whereas CC and pitch require a single message of 3 7bit values to be meaningful (without "running status"). Makes CC and pitch more similar to me, as does the actual use as "continuous" modifiers for parameters, whereas notes are more like something I switch on/off (this thought obviously doesn't fit so well for program change... or bank select on the CC message side, and some others too, but it's the most common use for CC, I think).
I see your point; but I was referring to the structure of the individual messages for various MIDI events, not to their typical usage. (One could also argue that sending pitch bend messages generally has no use if it isn't accompanied by note events, for example.)
Quote:
Originally Posted by gofer View Post
But this can't be the heart of the discussion, can it?
Nah, it's gone way OT.

But since the question in the OP seems to have been answered well enough, so I don't think anyone minds?
Quote:
Originally Posted by gofer View Post
Which name would you prefer?
I don't object to the name as such - it's a perfect name for a function to get/set CCs - but I do take issue with its functionality being much more general than its name indicates (which makes it *very* misleading), and with the lack of specific functions for specific tasks.

It makes no sense to me to have a function named "MIDI_SetCC" which then still needs to be told explicitly that you actually want to send a CC rather than something else. Now the user needs to specify "0xB0", while user-friendly functions for getting/setting CCs should just take care of that automatically.

Similarly, it makes no sense to me that you have to use a function named "MIDI_SetCC" when you want to use a different event type. It would be extremely easy for Cockos to just make a bunch of specific functions (e.g. "MIDI_SetPitchbend" etc.) that all inherit from an abstract "MIDI_SetEvent" function, for which the user doesn't have to know/remember anything about their underlying data format. Having only one function for multiple event types is not more convenient or efficient, it's just more cumbersome and confusing to the user.
__________________
˙lɐd 'ʎɐʍ ƃuoɹʍ ǝɥʇ ǝɔıʌǝp ʇɐɥʇ ƃuıploɥ ǝɹ,noʎ
Banned is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.