Skip to content

Commit

Permalink
encoders: add the option to send two notes depending on the direction
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Apr 16, 2024
1 parent 55ab566 commit de62617
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
31 changes: 27 additions & 4 deletions src/firmware/application/io/encoders/Encoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Encoders::processReading(size_t index, uint8_t pairValue, uint32_t sampleTi
}

encoderDescriptor_t descriptor;
fillEncoderDescriptor(index, descriptor);
fillEncoderDescriptor(index, encoderState, descriptor);

sendMessage(index, encoderState, descriptor);
}
Expand Down Expand Up @@ -327,6 +327,7 @@ void Encoders::sendMessage(size_t index, position_t encoderState, encoderDescrip

case type_t::SINGLE_NOTE_FIXED_VAL_BOTH_DIR:
case type_t::SINGLE_NOTE_FIXED_VAL_ONE_DIR_0_OTHER_DIR:
case type_t::TWO_NOTE_FIXED_VAL_BOTH_DIR:
{
descriptor.event.value = _database.read(database::Config::Section::encoder_t::REPEATED_VALUE, index);

Expand Down Expand Up @@ -446,12 +447,34 @@ Encoders::position_t Encoders::read(size_t index, uint8_t pairState)
return retVal;
}

void Encoders::fillEncoderDescriptor(size_t index, encoderDescriptor_t& descriptor)
void Encoders::fillEncoderDescriptor(size_t index, position_t encoderState, encoderDescriptor_t& descriptor)
{
descriptor.type = static_cast<type_t>(_database.read(database::Config::Section::encoder_t::MODE, index));
descriptor.type = static_cast<type_t>(_database.read(database::Config::Section::encoder_t::MODE, index));

switch (descriptor.type)
{
case type_t::TWO_NOTE_FIXED_VAL_BOTH_DIR:
{
if (encoderState == position_t::CCW)
{
descriptor.event.index = _database.read(database::Config::Section::encoder_t::MIDI_ID_2, index);
}
else
{
descriptor.event.index = _database.read(database::Config::Section::encoder_t::MIDI_ID_1, index);
}
}
break;

default:
{
descriptor.event.index = _database.read(database::Config::Section::encoder_t::MIDI_ID_1, index);
}
break;
}

descriptor.event.componentIndex = index;
descriptor.event.channel = _database.read(database::Config::Section::encoder_t::CHANNEL, index);
descriptor.event.index = _database.read(database::Config::Section::encoder_t::MIDI_ID_1, index);
descriptor.event.message = INTERNAL_MSG_TO_MIDI_TYPE[static_cast<uint8_t>(descriptor.type)];
}

Expand Down
4 changes: 3 additions & 1 deletion src/firmware/application/io/encoders/Encoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace io
SINGLE_NOTE_VARIABLE_VAL,
SINGLE_NOTE_FIXED_VAL_BOTH_DIR,
SINGLE_NOTE_FIXED_VAL_ONE_DIR_0_OTHER_DIR,
TWO_NOTE_FIXED_VAL_BOTH_DIR,
AMOUNT
};

Expand Down Expand Up @@ -124,7 +125,7 @@ namespace io
encoderDescriptor_t() = default;
};

void fillEncoderDescriptor(size_t index, encoderDescriptor_t& descriptor);
void fillEncoderDescriptor(size_t index, position_t encoderState, encoderDescriptor_t& descriptor);
position_t read(size_t index, uint8_t pairState);
void processReading(size_t index, uint8_t pairValue, uint32_t sampleTime);
void sendMessage(size_t index, position_t encoderState, encoderDescriptor_t& descriptor);
Expand Down Expand Up @@ -229,6 +230,7 @@ namespace io
MIDI::messageType_t::NOTE_ON, // SINGLE_NOTE_VARIABLE_VAL
MIDI::messageType_t::NOTE_ON, // SINGLE_NOTE_FIXED_VAL_BOTH_DIR
MIDI::messageType_t::NOTE_ON, // SINGLE_NOTE_FIXED_VAL_ONE_DIR_0_OTHER_DIR
MIDI::messageType_t::NOTE_ON, // TWO_NOTE_FIXED_VAL_BOTH_DIR
};
};
} // namespace io
Expand Down

0 comments on commit de62617

Please sign in to comment.