Added Row and Column Mapping
Fixed Loudness Visual
This commit is contained in:
parent
c13016275b
commit
238e22caf6
6 changed files with 384 additions and 44 deletions
|
|
@ -4,7 +4,27 @@
|
|||
#include <VUtils/Logging.h>
|
||||
|
||||
Vulcan121::Vulcan121(HIDHelper *helper)
|
||||
: m_helper(helper) {}
|
||||
: m_helper(helper) {
|
||||
for (auto &item : keyMapRow) {
|
||||
item = new keys;
|
||||
}
|
||||
for (auto &item : keyMapCol) {
|
||||
item = new keys;
|
||||
}
|
||||
|
||||
setupMap();
|
||||
}
|
||||
|
||||
Vulcan121::~Vulcan121() {
|
||||
for (auto &item: keyMapRow) {
|
||||
delete[] item->index;
|
||||
delete item;
|
||||
}
|
||||
for (auto &item: keyMapCol) {
|
||||
delete[] item->index;
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
||||
int i, k;
|
||||
|
|
@ -13,7 +33,7 @@ int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
|||
unsigned char workbuf[65];
|
||||
memset(hwmap, 0, sizeof(hwmap));
|
||||
for (k = 0; k < NUM_KEYS; k++) {
|
||||
rgb = rv_fixed[ k ] ? *(rv_fixed[ k ]) : (src ? src->key[ k ] : rv_color_off);
|
||||
rgb = rv_fixed[k] ? *(rv_fixed[k]) : (src ? src->key[k] : rv_color_off);
|
||||
|
||||
rgb.r = (rgb.r > 255) ? 255 : (rgb.r < 0) ? 0 : rgb.r;
|
||||
rgb.g = (rgb.g > 255) ? 255 : (rgb.g < 0) ? 0 : rgb.g;
|
||||
|
|
@ -25,18 +45,18 @@ int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
|||
rgb.b *= factor;
|
||||
|
||||
int offset = ((k / 12) * 36) + (k % 12);
|
||||
hwmap[ offset + 0 ] = (unsigned char) rgb.r;
|
||||
hwmap[ offset + 12 ] = (unsigned char) rgb.g;
|
||||
hwmap[ offset + 24 ] = (unsigned char) rgb.b;
|
||||
hwmap[offset + 0] = (unsigned char) rgb.r;
|
||||
hwmap[offset + 12] = (unsigned char) rgb.g;
|
||||
hwmap[offset + 24] = (unsigned char) rgb.b;
|
||||
}
|
||||
|
||||
// First chunk comes with header
|
||||
workbuf[ 0 ] = 0x00;
|
||||
workbuf[ 1 ] = 0xa1;
|
||||
workbuf[ 2 ] = 0x01;
|
||||
workbuf[ 3 ] = 0x01;
|
||||
workbuf[ 4 ] = 0xb4;
|
||||
memcpy(&workbuf[ 5 ], hwmap, 60);
|
||||
workbuf[0] = 0x00;
|
||||
workbuf[1] = 0xa1;
|
||||
workbuf[2] = 0x01;
|
||||
workbuf[3] = 0x01;
|
||||
workbuf[4] = 0xb4;
|
||||
memcpy(&workbuf[5], hwmap, 60);
|
||||
if (hid_write(m_helper->m_ledDevice, workbuf, 65) != 65) {
|
||||
if (deleteMap) {
|
||||
delete src;
|
||||
|
|
@ -46,8 +66,8 @@ int Vulcan121::send_led_map(led_map *src, bool deleteMap) {
|
|||
|
||||
// Six more chunks
|
||||
for (i = 1; i < 7; i++) {
|
||||
workbuf[ 0 ] = 0x00;
|
||||
memcpy(&workbuf[ 1 ], &hwmap[ (i * 64) - 4 ], 64);
|
||||
workbuf[0] = 0x00;
|
||||
memcpy(&workbuf[1], &hwmap[(i * 64) - 4], 64);
|
||||
if (hid_write(m_helper->m_ledDevice, workbuf, 65) != 65) {
|
||||
if (deleteMap) {
|
||||
delete src;
|
||||
|
|
@ -91,7 +111,7 @@ bool Vulcan121::query_ctrl_report(unsigned char id) {
|
|||
if (id != 0x0f) return false;
|
||||
unsigned char buffer[8] = {};
|
||||
int length = 8;
|
||||
buffer[ 0 ] = id;
|
||||
buffer[0] = id;
|
||||
int res = m_helper->get_feature_report(buffer, length);
|
||||
if (res) {
|
||||
return true;
|
||||
|
|
@ -203,7 +223,7 @@ bool Vulcan121::wait_for_ctrl_dev() {
|
|||
usleep(10000);
|
||||
res = m_helper->get_feature_report(buffer, sizeof(buffer));
|
||||
if (res) {
|
||||
if (buffer[ 1 ] == 0x01) break;
|
||||
if (buffer[1] == 0x01) break;
|
||||
} else {
|
||||
ERR("rv_wait_for_ctrl_device() failed");
|
||||
return false;
|
||||
|
|
@ -213,30 +233,105 @@ bool Vulcan121::wait_for_ctrl_dev() {
|
|||
}
|
||||
|
||||
int Vulcan121::getColumnsForRow(int row) {
|
||||
if (row > 5) {
|
||||
WARN("Try to Access out of Bound %d max %d", row, 5)
|
||||
if (row > NUM_ROWS-1) {
|
||||
WARN("Try to Access out of Bound %d max %d", row, NUM_ROWS-1)
|
||||
return 0;
|
||||
}
|
||||
return keyMapRow[row]->count;
|
||||
}
|
||||
|
||||
// @Todo Add Columngs
|
||||
|
||||
int Vulcan121::getRowsForColumns(int col) {
|
||||
if (col > 5) {
|
||||
WARN("Try to Access out of Bound %d max %d", col, 5)
|
||||
if (col > NUM_COLS-1) {
|
||||
WARN("Try to Access out of Bound %d max %d", col, NUM_COLS-1)
|
||||
return 0;
|
||||
}
|
||||
return keyMapCols[col]->count;
|
||||
return keyMapCol[col]->count;
|
||||
}
|
||||
|
||||
int Vulcan121::getIndex(int row, int col) {
|
||||
if (row > 5) {
|
||||
WARN("Try to Access out of Bound %d max %d", row, 5)
|
||||
if (row > NUM_ROWS-1) {
|
||||
WARN("Try to Access out of Bound %d max %d", row, NUM_ROWS-1)
|
||||
return 0;
|
||||
}
|
||||
if (col > keyMapRow[ row ]->count) {
|
||||
if (col > keyMapRow[row]->count) {
|
||||
WARN("Try to Access out of Bound %d max %d", col, keyMapRow[row]->count)
|
||||
return 0;
|
||||
}
|
||||
return keyMapRow[row]->index[col];
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Mapping
|
||||
* They are not magic! look in the layout.md
|
||||
*/
|
||||
void Vulcan121::setupMap() {
|
||||
// Row Init
|
||||
keyMapRow[0]->count = 16;
|
||||
keyMapRow[0]->index = new int[16]{ 0, 11, 17, 23, 28, 48, 53, 59, 65, 78, 84, 85, 86, 99, 103, 108 };
|
||||
keyMapRow[1]->count = 21;
|
||||
keyMapRow[1]->index = new int[21]{ 1, 6, 12, 18, 24, 29, 33, 49, 54, 60, 66, 72,
|
||||
79, 87, 100, 104, 109, 113, 119, 124, 129 };
|
||||
keyMapRow[2]->count = 19;
|
||||
keyMapRow[2]->index = new int[19]{ 2, 7, 13, 19, 25, 30, 34, 50, 55, 61, 67, 73, 80, 101, 105, 110, 114, 120, 125 };
|
||||
keyMapRow[3]->count = 17;
|
||||
keyMapRow[3]->index = new int[17]{ 3, 8, 14, 20, 26, 31, 35, 51, 56, 62, 68, 74, 88, 115, 121, 126, 130 };
|
||||
keyMapRow[4]->count = 17;
|
||||
keyMapRow[4]->index = new int[17]{ 4, 9, 15, 21, 27, 32, 36, 52, 57, 63, 69, 75, 82, 106, 116, 122, 127 };
|
||||
keyMapRow[5]->count = 14;
|
||||
keyMapRow[5]->index = new int[14]{ 5, 10, 16, 37, 70, 76, 83, 89, 102, 107, 111, 117, 128, 131 };
|
||||
// Col init
|
||||
keyMapCol[0]->count = 6;
|
||||
keyMapCol[0]->index = new int[6]{ 0, 1, 2, 3, 4, 5 };
|
||||
keyMapCol[1]->count = 5;
|
||||
keyMapCol[1]->index = new int[5]{ 6, 7, 8, 9, 10 };
|
||||
keyMapCol[2]->count = 6;
|
||||
keyMapCol[2]->index = new int[6]{ 11, 12, 13, 14, 15, 16 };
|
||||
keyMapCol[3]->count = 5;
|
||||
keyMapCol[3]->index = new int[5]{ 17, 18, 19, 20, 27 };
|
||||
keyMapCol[4]->count = 5;
|
||||
keyMapCol[4]->index = new int[5]{ 23, 24, 25, 26, 32 };
|
||||
keyMapCol[5]->count = 6;
|
||||
keyMapCol[5]->index = new int[6]{ 28, 29, 30, 31, 36, 37 };
|
||||
keyMapCol[6]->count = 5;
|
||||
keyMapCol[6]->index = new int[5]{ 48, 33, 34, 35, 52 };
|
||||
keyMapCol[7]->count = 5;
|
||||
keyMapCol[7]->index = new int[5]{ 53, 49, 50, 51, 57 };
|
||||
keyMapCol[8]->count = 5;
|
||||
keyMapCol[8]->index = new int[5]{ 59, 54, 55, 56, 63 };
|
||||
keyMapCol[9]->count = 6;
|
||||
keyMapCol[9]->index = new int[6]{ 65, 60, 61, 62, 69, 70 };
|
||||
keyMapCol[10]->count = 6;
|
||||
keyMapCol[10]->index = new int[6]{ 78, 66, 67, 68, 75, 76 };
|
||||
keyMapCol[11]->count = 5;
|
||||
keyMapCol[11]->index = new int[5]{ 84, 72, 73, 74, 83 };
|
||||
keyMapCol[12]->count = 5;
|
||||
keyMapCol[12]->index = new int[5]{ 85, 79, 80, 96, 82 };
|
||||
keyMapCol[13]->count = 4;
|
||||
keyMapCol[13]->index = new int[4]{ 86, 87, 88, 89 };
|
||||
keyMapCol[14]->count = 4;
|
||||
keyMapCol[14]->index = new int[4]{ 99, 100, 101, 102 };
|
||||
keyMapCol[15]->count = 5;
|
||||
keyMapCol[15]->index = new int[5]{ 103, 104, 105, 106, 107 };
|
||||
keyMapCol[16]->count = 4;
|
||||
keyMapCol[16]->index = new int[4]{ 108, 109, 110, 111 };
|
||||
keyMapCol[17]->count = 5;
|
||||
keyMapCol[17]->index = new int[5]{ 113, 114, 115, 116, 117 };
|
||||
keyMapCol[18]->count = 4;
|
||||
keyMapCol[18]->index = new int[4]{ 119, 120, 121, 122 };
|
||||
keyMapCol[19]->count = 5;
|
||||
keyMapCol[19]->index = new int[5]{ 124, 125, 126, 127, 128 };
|
||||
keyMapCol[20]->count = 3;
|
||||
keyMapCol[20]->index = new int[3]{ 129, 130, 131 };
|
||||
}
|
||||
|
||||
int Vulcan121::getIndexNoCheck(int row, int col) {
|
||||
return keyMapRow[row]->index[col];
|
||||
}
|
||||
|
||||
const keys * Vulcan121::getColumn(int col) {
|
||||
return keyMapCol[col];
|
||||
}
|
||||
const keys * Vulcan121::getRow(int row) {
|
||||
return keyMapRow[row];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@ namespace VIZ {
|
|||
float val = grabber->getLoudness();
|
||||
val = val > 1.0f ? 1.0f : val;
|
||||
double newVal = (val + lastVal) * 0.5;
|
||||
int maxCol = newVal * 24;
|
||||
int maxCol = newVal * keyboardData.num_cols;
|
||||
for (int col = 0; col < maxCol; ++col) {
|
||||
for (int i = 0; i < keyboardData.num_rows; ++i) {
|
||||
auto index = col * i;
|
||||
auto column = keyboard->getColumn(col);
|
||||
for (int i = 0; i < column->count; ++i) {
|
||||
auto index = column->index[i];
|
||||
if (col >= maxCol - 1) data[ 0 ].key[ index ] = { 255, 0, 0, 100 };
|
||||
else data[ 0 ].key[ index ] = { 0, 0, 255, 80 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,23 +16,20 @@ namespace VIZ {
|
|||
auto data = grabber->fft.getData()->leftChannel;
|
||||
auto val = 0.0;
|
||||
for (int i = 1; i < 4; ++i) {
|
||||
if (data[ i ] > val) {
|
||||
val = data[ i ];
|
||||
if (data[i] > val) {
|
||||
val = data[i];
|
||||
}
|
||||
}
|
||||
switchOnPeak(val);
|
||||
tick++;
|
||||
int colorInd = left ? 0 : 1;
|
||||
colors[ colorInd ].a = val;
|
||||
if (left) {
|
||||
for (int i = 0; i < 62; ++i) {
|
||||
int ind = i;
|
||||
map[ 0 ].key[ ind ] = colors[ colorInd ];
|
||||
}
|
||||
} else {
|
||||
for (int i = 62; i < keyboardData.num_keys; ++i) {
|
||||
int ind = i;
|
||||
map[ 0 ].key[ ind ] = colors[ colorInd ];
|
||||
colors[colorInd].a = val;
|
||||
int colOff = left ? 0 : 9;
|
||||
int max = left ? 10 : 12;
|
||||
for (int i = 0; i < max; ++i) {
|
||||
auto col = keyboard->getColumn(i + colOff);
|
||||
for (int j = 0; j < col->count; ++j) {
|
||||
map[0].key[col->index[j]] = colors[colorInd];
|
||||
}
|
||||
}
|
||||
keyboard->send_led_map(map, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue