sigboost-inc / midiglue-forum

This is the official forum of midiglue.
4 stars 0 forks source link

Custom node: vel_curves Modifies Velocity based on Exp/Log curves #9

Closed BrufordRules closed 4 years ago

BrufordRules commented 4 years ago

This is my first node. Sorry if the code is not too elegant but it works for me.

It also can be used with MIDI CC values.

I have attached an image with the velocity curves I used in the node.

vel_curves

Modifies Velocity based on an Exponential or a Logarithmic curve. Curve type: 0-7: Exponential curves 8: Linear response (default) 9-16: Logarithmic curves

INPUTS

· 0: Input Velocity (Int) · 1: Curve type. Exponential/Linear/Logarithmic (0-7, 8, 9-16), stored (Int)

OUTPUT

· 0: Output Velocity (Int)

PARAMETERS

· Curve: Curve type. Exponential/Linear/Logarithmic (0-7, 8, 9-16) Default: Linear response · Type: Int · Default: 8 · Constraint: None

vel_curves.zip

kuguma commented 4 years ago

I'm glad you solved it! I tried to fix it to reduce memory usage, and added your copyright. Thanks for the code. At a later date, I would like to provide a version that uses a formula.

<Comment>
Copyright (c) 2020 BrufordRules., All Rights Reserved.
This file is licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0) license.

<I/O>
input Int : Input Velocity
input Int : Curve type. Exponential/Linear/Logarithmic (0-7, 8, 9-16), stored
output Int : Output Velocity

<Description>
Modifies Velocity based on an Exponential or a Logarithmic curve.
Curve type:
0-7: Exponential curves
8: Linear response (default)
9-16: Logarithmic curves

<Parameter>
parameter Curve = 8 : Curve type. Exponential/Linear/Logarithmic (0-7, 8, 9-16) Default: Linear response

<Code>
static uint8_t Type = ${Curve};
static uint8_t Exp8[128] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 61, 63, 66, 68, 71, 74, 78, 82, 86, 91, 97, 105, 127};
static uint8_t Exp7[128] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 19, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 29, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 48, 49, 51, 52, 54, 55, 57, 59, 60, 62, 64, 66, 69, 71, 73, 76, 79, 82, 85, 88, 92, 97, 102, 108, 115, 127};
static uint8_t Exp6[128] = {0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 33, 34, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 53, 54, 56, 57, 58, 60, 62, 63, 65, 67, 68, 70, 72, 74, 76, 79, 81, 83, 86, 89, 92, 95, 98, 102, 106, 110, 115, 120, 127};
static uint8_t Exp5[128] = {0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 58, 59, 60, 62, 63, 65, 66, 68, 69, 71, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 95, 97, 100, 103, 105, 108, 112, 115, 119, 123, 127};
static uint8_t Exp4[128] = {0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 31, 31, 32, 33, 34, 35, 35, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 63, 64, 65, 66, 68, 69, 71, 72, 73, 75, 76, 78, 79, 81, 83, 84, 86, 88, 90, 92, 93, 95, 97, 99, 102, 104, 106, 108, 111, 113, 116, 118, 121, 124, 127};
static uint8_t Exp3[128] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 74, 75, 76, 77, 79, 80, 82, 83, 84, 86, 87, 89, 90, 92, 93, 95, 97, 98, 100, 102, 103, 105, 107, 109, 111, 113, 114, 116, 118, 121, 123, 125, 127};
static uint8_t Exp2[128] = {0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 28, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 97, 98, 100, 101, 102, 104, 105, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 122, 124, 125, 127};
static uint8_t Exp1[128] = {0, 1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 33, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 116, 117, 118, 119, 121, 122, 123, 124, 126, 127};
static uint8_t Log1[128] = {0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 102, 103, 104, 105, 106, 107, 108, 108, 109, 110, 111, 112, 113, 113, 114, 115, 116, 117, 117, 118, 119, 120, 121, 122, 122, 123, 124, 125, 125, 126, 127};
static uint8_t Log2[128] = {0, 2, 3, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 27, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 83, 84, 85, 86, 87, 88, 89, 90, 90, 91, 92, 93, 94, 95, 96, 96, 97, 98, 99, 100, 100, 101, 102, 103, 103, 104, 105, 106, 106, 107, 108, 109, 109, 110, 111, 111, 112, 113, 114, 114, 115, 116, 116, 117, 118, 118, 119, 120, 120, 121, 121, 122, 123, 123, 124, 125, 125, 126, 126, 127};
static uint8_t Log3[128] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 23, 25, 27, 29, 30, 32, 33, 35, 37, 38, 40, 41, 42, 44, 45, 47, 48, 49, 51, 52, 53, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 85, 86, 87, 88, 89, 90, 91, 91, 92, 93, 94, 95, 95, 96, 97, 98, 98, 99, 100, 101, 101, 102, 103, 103, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 111, 111, 112, 112, 113, 114, 114, 115, 115, 116, 116, 117, 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 123, 123, 124, 124, 125, 125, 126, 126, 127, 127};
static uint8_t Log4[128] = {0, 3, 6, 8, 11, 14, 16, 18, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 42, 44, 46, 47, 49, 50, 52, 53, 55, 56, 58, 59, 60, 62, 63, 64, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 96, 97, 98, 99, 99, 100, 101, 101, 102, 103, 103, 104, 105, 105, 106, 107, 107, 108, 108, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119, 119, 119, 120, 120, 121, 121, 122, 122, 122, 123, 123, 123, 124, 124, 125, 125, 125, 126, 126, 126, 127, 127};
static uint8_t Log5[128] = {0, 4, 8, 12, 15, 18, 21, 24, 27, 29, 32, 34, 37, 39, 41, 43, 45, 47, 49, 51, 53, 54, 56, 58, 59, 61, 62, 64, 65, 66, 68, 69, 70, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 91, 92, 93, 94, 95, 95, 96, 97, 98, 98, 99, 100, 101, 101, 102, 103, 103, 104, 105, 105, 106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 115, 116, 116, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 124, 124, 124, 125, 125, 125, 125, 126, 126, 126, 126, 127, 127, 127};
static uint8_t Log6[128] = {0, 6, 12, 17, 21, 25, 28, 32, 35, 38, 40, 43, 45, 48, 50, 52, 54, 56, 58, 60, 62, 64, 65, 67, 68, 70, 71, 73, 74, 75, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 101, 102, 103, 103, 104, 105, 105, 106, 106, 107, 108, 108, 109, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 115, 116, 116, 117, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127};
static uint8_t Log7[128] = {0, 11, 19, 24, 29, 34, 38, 41, 45, 48, 50, 53, 56, 58, 60, 62, 64, 66, 68, 70, 72, 73, 75, 76, 78, 79, 80, 82, 83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 97, 98, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 115, 116, 116, 117, 117, 117, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127};
static uint8_t Log8[128] = {0, 22, 30, 36, 41, 45, 49, 53, 56, 59, 61, 64, 66, 68, 70, 72, 74, 76, 78, 79, 81, 82, 84, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 103, 104, 105, 106, 106, 107, 108, 108, 109, 109, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 115, 116, 116, 117, 117, 117, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, 123, 123, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127};
if (@in1)
    {
    Type = in1;
    }
if (@in0)
    {
    if (Type == 0)
    out0 = in0[Exp8];
    if (Type == 1)
    out0 = in0[Exp7];
    if (Type == 2)
    out0 = in0[Exp6];
    if (Type == 3)
    out0 = in0[Exp5];
    if (Type == 4)
    out0 = in0[Exp4];
    if (Type == 5)
    out0 = in0[Exp3];
    if (Type == 6)
    out0 = in0[Exp2];
    if (Type == 7)
    out0 = in0[Exp1];
    if (Type == 8)
    out0 = in0;
    if (Type == 9)
    out0 = in0[Log1];
    if (Type == 10)
    out0 = in0[Log2];
    if (Type == 11)
    out0 = in0[Log3];
    if (Type == 12)
    out0 = in0[Log4];
    if (Type == 13)
    out0 = in0[Log5];
    if (Type == 14)
    out0 = in0[Log6];
    if (Type == 15)
    out0 = in0[Log7];
    if (Type == 16)
    out0 = in0[Log8];
    }
BrufordRules commented 4 years ago

Thank you so much, Kai.

kuguma commented 4 years ago

You're welcome! In the next update, we will add a mathematical Log / Exp approximation to scale node. Your work is great, so if you send a pull request to the midiglue-nodelib repository and I'll accept it. https://github.com/sigboost-inc/midiglue-nodelib

cheers!