Skip to content

Commit 917592b

Browse files
Add functions for creating zone maps and use them to improve zone mapping
1 parent cb12727 commit 917592b

File tree

2 files changed

+93
-15
lines changed

2 files changed

+93
-15
lines changed

KeyboardVisualizerCommon/Visualizer.cpp

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,62 @@ void Visualizer::OpenRGBDisconnect(NetworkClient * client)
13971397
}
13981398
}
13991399

1400+
static void SetupMatrixGrid(int x_count, int y_count, int * x_idx_list, int * y_idx_list)
1401+
{
1402+
for(int x = 0; x < x_count; x++)
1403+
{
1404+
if(x_count < 10)
1405+
{
1406+
x_idx_list[x] = (int)((x * (SPECTROGRAPH_COLS / (x_count))) + (0.5f * (SPECTROGRAPH_COLS / (x_count))));
1407+
}
1408+
else if(x < ((x_count) / 2))
1409+
{
1410+
x_idx_list[x] = (int)((x * (SPECTROGRAPH_COLS / (x_count - 1))) + (0.5f * (SPECTROGRAPH_COLS / (x_count - 1))));
1411+
}
1412+
else
1413+
{
1414+
x_idx_list[x] = (int)((x * (SPECTROGRAPH_COLS / (x_count - 1))) - (0.5f * (SPECTROGRAPH_COLS / (x_count - 1))));
1415+
}
1416+
1417+
}
1418+
for(int y = 0; y < y_count; y++)
1419+
{
1420+
y_idx_list[y] = (int)(ROW_IDX_SPECTROGRAPH_TOP + (y * (SPECTROGRAPH_ROWS / y_count)) + (0.5f * (SPECTROGRAPH_ROWS / y_count)));
1421+
}
1422+
}
1423+
1424+
static void SetupLinearGrid(int x_count, int * x_idx_list)
1425+
{
1426+
if((x_count % 2) == 0)
1427+
{
1428+
//Even number of LEDs
1429+
for(int x = 0; x < x_count; x++)
1430+
{
1431+
x_idx_list[x] = (int)((float)x * (256.0f / (float)x_count)) + (128.0f / (float)x_count);
1432+
}
1433+
}
1434+
else
1435+
{
1436+
//Odd number of LEDs
1437+
for(int x = 0; x < x_count; x++)
1438+
{
1439+
if (x == (x_count / 2))
1440+
{
1441+
x_idx_list[x] = 128;
1442+
}
1443+
else if (x < ((x_count / 2) + 1))
1444+
{
1445+
x_idx_list[x] = (x_count / 2) + ((x + 1) * (256 / (x_count + 1)));
1446+
}
1447+
else
1448+
{
1449+
x_idx_list[x] = ((x_count / 2) + 1) + (x * (256 / (x_count + 1)));
1450+
}
1451+
1452+
}
1453+
}
1454+
}
1455+
14001456
void Visualizer::LEDUpdateThreadFunction()
14011457
{
14021458
while(1)
@@ -1412,20 +1468,28 @@ void Visualizer::LEDUpdateThreadFunction()
14121468
case ZONE_TYPE_MATRIX:
14131469
if(rgb_controllers[c]->zones[z].matrix_map != NULL)
14141470
{
1415-
for (int y = 0; y < rgb_controllers[c]->zones[z].matrix_map->height; y++)
1471+
int x_count = rgb_controllers[c]->zones[z].matrix_map->width;
1472+
int y_count = rgb_controllers[c]->zones[z].matrix_map->height;
1473+
int * ZoneXIndex = new int[x_count];
1474+
int * ZoneYIndex = new int[y_count];
1475+
1476+
SetupMatrixGrid(x_count, y_count, ZoneXIndex, ZoneYIndex);
1477+
1478+
for (int y = 0; y < y_count; y++)
14161479
{
1417-
for (int x = 0; x < rgb_controllers[c]->zones[z].matrix_map->width; x++)
1480+
for (int x = 0; x < x_count; x++)
14181481
{
14191482
unsigned int map_idx = (y * rgb_controllers[c]->zones[z].matrix_map->width) + x;
14201483
unsigned int color_idx = rgb_controllers[c]->zones[z].matrix_map->map[map_idx];
14211484
if( color_idx != 0xFFFFFFFF )
14221485
{
1423-
unsigned int pixels_y = 2 + y * (62 / rgb_controllers[c]->zones[z].matrix_map->height);
1424-
unsigned int pixels_x = x * (256 / rgb_controllers[c]->zones[z].matrix_map->width);
1425-
rgb_controllers[c]->zones[z].colors[color_idx] = pixels_out->pixels[pixels_y][pixels_x];
1486+
rgb_controllers[c]->zones[z].colors[color_idx] = pixels_out->pixels[ZoneYIndex[y]][ZoneXIndex[x]];
14261487
}
14271488
}
14281489
}
1490+
1491+
delete[] ZoneXIndex;
1492+
delete[] ZoneYIndex;
14291493
}
14301494
else
14311495
{
@@ -1444,10 +1508,17 @@ void Visualizer::LEDUpdateThreadFunction()
14441508
break;
14451509

14461510
case ZONE_TYPE_LINEAR:
1447-
for (int r = 0; r < rgb_controllers[c]->zones[z].leds_count; r++)
1511+
unsigned int num_leds = rgb_controllers[c]->zones[z].leds_count;
1512+
int * ZoneXIndex = new int[num_leds];
1513+
1514+
SetupLinearGrid(num_leds, ZoneXIndex);
1515+
1516+
for (int x = 0; x < rgb_controllers[c]->zones[z].leds_count; x++)
14481517
{
1449-
rgb_controllers[c]->zones[z].colors[r] = pixels_out->pixels[ROW_IDX_BAR_GRAPH][r * (256 / rgb_controllers[c]->zones[z].leds_count)];
1518+
rgb_controllers[c]->zones[z].colors[x] = pixels_out->pixels[ROW_IDX_BAR_GRAPH][ZoneXIndex[x]];
14501519
}
1520+
1521+
delete[] ZoneXIndex;
14511522
break;
14521523
}
14531524
}

KeyboardVisualizerQT/KeyboardVisDlg.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,11 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
374374
ui->tree_Devices->clear();
375375

376376
//OpenRGB device list
377-
ui->tree_Devices->setColumnCount(3);
378-
ui->tree_Devices->setHeaderLabels(QStringList() << "Device Zones" << "LEDs" << "Type");
377+
ui->tree_Devices->setColumnCount(2);
378+
ui->tree_Devices->header()->setStretchLastSection(false);
379+
ui->tree_Devices->header()->setSectionResizeMode(0, QHeaderView::Stretch);
380+
ui->tree_Devices->setColumnWidth(1, 100);
381+
ui->tree_Devices->setHeaderLabels(QStringList() << "Connected Clients" << "");
379382

380383
QSignalMapper* signalMapper = new QSignalMapper(this);
381384
connect(signalMapper, SIGNAL(mapped(QObject *)), this, SLOT(on_button_Disconnect_clicked(QObject *)));
@@ -386,7 +389,7 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
386389
new_top_item->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->GetIP()));
387390

388391
QPushButton* new_button = new QPushButton( "Disconnect" );
389-
ui->tree_Devices->setItemWidget(new_top_item, 2, new_button);
392+
ui->tree_Devices->setItemWidget(new_top_item, 1, new_button);
390393

391394
connect(new_button, SIGNAL(clicked()), signalMapper, SLOT(map()));
392395

@@ -404,24 +407,28 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
404407
{
405408
QTreeWidgetItem* new_child = new QTreeWidgetItem();
406409

407-
new_child->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].name));
408-
new_child->setText(1, QString::fromStdString(std::to_string((vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].leds_count))));
410+
std::string zone_str = vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].name + ", ";
411+
zone_str.append(std::to_string(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].leds_count));
412+
zone_str.append(" LEDs, ");
409413

410414
switch(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].type)
411415
{
412416
case ZONE_TYPE_SINGLE:
413-
new_child->setText(2, "Single");
417+
zone_str.append("Single");
414418
break;
415419

416420
case ZONE_TYPE_LINEAR:
417-
new_child->setText(2, "Linear");
421+
zone_str.append("Linear");
418422
break;
419423

420424
case ZONE_TYPE_MATRIX:
421-
new_child->setText(2, "Matrix");
425+
zone_str.append("Matrix");
422426
break;
423427
}
424428

429+
new_child->setText(0, QString::fromStdString(zone_str));
430+
431+
425432
new_item->addChild(new_child);
426433
}
427434
}

0 commit comments

Comments
 (0)