<commit_before>/* Copyright (c) 2011 <NAME> */

#include <Midi.h>

#undef ROTO_TEST_TONES

#include "tonewheels.h"

#define BUFFER_LEN 128

uint16_t buffer1[BUFFER_LEN];
uint16_t buffer2[BUFFER_LEN];
uint16_t *cur = 0;
uint16_t cur_sample;

volatile boolean gen_buffer1;
volatile boolean gen_buffer2;

uint8_t num_keys_down=0;

class RotoMidi : public Midi {
 public:
 RotoMidi(HardwareSerial &s) : Midi(s) { }

    void handleControlChange(unsigned int channel, unsigned int controller,
                             unsigned int value) {
        /* map MIDI CC# 110-118 to drawbars */
        uint8_t drawbar = controller - 109;

        /* invert value and convert it to drawbar settings 0..8 */
        if (value > 112) {
            value = 0;
        } else if (value > 98) {
            value = 1;
        } else if (value > 84) {
            value = 2;
        } else if (value > 70) {
            value = 3;
        } else if (value > 56) {
            value = 4;
        } else if (value > 42) {
            value = 5;
        } else if (value > 28) {
            value = 6;
        } else if (value > 14) {
            value = 7;
        } else {
            value = 8;
        }

        tonewheels_set_drawbar(drawbar, value);<commit_msg>use the Arduino map() routine to simplify drawbar math in RotoMidi<commit_after>/* Copyright (c) 2011 <NAME> */

#include <Midi.h>

#undef ROTO_TEST_TONES

#include "tonewheels.h"

#define BUFFER_LEN 128

uint16_t buffer1[BUFFER_LEN];
uint16_t buffer2[BUFFER_LEN];
uint16_t *cur = 0;
uint16_t cur_sample;

volatile boolean gen_buffer1;
volatile boolean gen_buffer2;

uint8_t num_keys_down=0;

class RotoMidi : public Midi {
 public:
 RotoMidi(HardwareSerial &s) : Midi(s) { }

    void handleControlChange(unsigned int channel, unsigned int controller,
                             unsigned int value) {
        /* map MIDI CC# 110-118 to drawbars */
        uint8_t drawbar = controller - 109;

        /* invert value and convert it to drawbar settings 0..8. Invert to
         * match organ behavior, where pulling a drawbar closer raises its
         * volume. This might not be appropriate on all keyboards. */
        value = map(127-value, 0, 127, 0, 8);

        tonewheels_set_drawbar(drawbar, value);
{'fraction_non_alphanumeric': 0.09601769911504425, 'fraction_numerical': 0.045575221238938056, 'mean_word_length': 2.2768115942028984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4053220', 'n_tokens_mistral': 817, 'n_tokens_neox': 719, 'n_words': 226}