| 479 | |
---|
| 480 | def saveSettings(self, indent): |
---|
| 481 | matrixSaveString = [] |
---|
| 482 | matrixSaveString.append('%s <row_number>\n' % indent) |
---|
| 483 | matrixSaveString.append('%s %d\n' % (indent, self.rows)) |
---|
| 484 | matrixSaveString.append('%s </row_number>\n' % indent) |
---|
| 485 | matrixSaveString.append('%s <col_number>\n' % indent) |
---|
| 486 | matrixSaveString.append('%s %d\n' % (indent, self.cols)) |
---|
| 487 | matrixSaveString.append('%s </col_number>\n' % indent) |
---|
| 488 | matrixSaveString.append('%s <coefficients>\n' % indent) |
---|
| 489 | for i in range(self.rows): |
---|
| 490 | line = '%s ' % indent |
---|
| 491 | for j in range(self.cols): |
---|
| 492 | line += '%d ' % self.interface.getValue(i,j) |
---|
| 493 | line += '\n' |
---|
| 494 | matrixSaveString.append(line) |
---|
| 495 | matrixSaveString.append('%s </coefficients>\n' % indent) |
---|
| 496 | if (self.mutes_interface != None): |
---|
| 497 | matrixSaveString.append('%s <mutes>\n' % indent) |
---|
| 498 | for i in range(self.rows): |
---|
| 499 | line = '%s ' % indent |
---|
| 500 | for j in range(self.cols): |
---|
| 501 | line += '%d ' % self.mutes_interface.getValue(i,j) |
---|
| 502 | line += '\n' |
---|
| 503 | matrixSaveString.append(line) |
---|
| 504 | matrixSaveString.append('%s </mutes>\n' % indent) |
---|
| 505 | |
---|
| 506 | if (self.inverts_interface != None): |
---|
| 507 | matrixSaveString.append('%s <inverts>\n' % indent) |
---|
| 508 | for i in range(self.rows): |
---|
| 509 | line = '%s ' % indent |
---|
| 510 | for j in range(self.cols): |
---|
| 511 | line += '%d ' % self.inverts_interface.getValue(i,j) |
---|
| 512 | line += '\n' |
---|
| 513 | matrixSaveString.append(line) |
---|
| 514 | matrixSaveString.append('%s </inverts>\n' % indent) |
---|
| 515 | |
---|
| 516 | return matrixSaveString |
---|
| 517 | |
---|
| 518 | def readSettings(self, readMatrixString, transpose_coeff): |
---|
| 519 | if readMatrixString[0].find("<row_number>") == -1: |
---|
| 520 | log.debug("Number of matrix rows must be specified") |
---|
| 521 | return False |
---|
| 522 | if readMatrixString[2].find("</row_number>") == -1: |
---|
| 523 | log.debug("Non-conformal xml file") |
---|
| 524 | return False |
---|
| 525 | n_rows = int(readMatrixString[1]) |
---|
| 526 | |
---|
| 527 | if readMatrixString[3].find("<col_number>") == -1: |
---|
| 528 | log.debug("Number of matrix columns must be specified") |
---|
| 529 | return False |
---|
| 530 | if readMatrixString[5].find("</col_number>") == -1: |
---|
| 531 | log.debug("Non-conformal xml file") |
---|
| 532 | return False |
---|
| 533 | n_cols = int(readMatrixString[4]) |
---|
| 534 | |
---|
| 535 | if transpose_coeff: |
---|
| 536 | if n_rows > self.cols: |
---|
| 537 | n_rows = self.cols |
---|
| 538 | if n_cols > self.rows: |
---|
| 539 | n_cols = self.rows |
---|
| 540 | else: |
---|
| 541 | if n_rows > self.rows: |
---|
| 542 | n_rows = self.rows |
---|
| 543 | if n_cols > self.cols: |
---|
| 544 | n_cols = self.cols |
---|
| 545 | log.debug("Setting %d rows and %d columns coefficients" % (n_rows, n_cols)) |
---|
| 546 | |
---|
| 547 | try: |
---|
| 548 | idxb = readMatrixString.index('<coefficients>') |
---|
| 549 | idxe = readMatrixString.index('</coefficients>') |
---|
| 550 | except Exception: |
---|
| 551 | log.debug("No mixer matrix coefficients specified") |
---|
| 552 | idxb = -1 |
---|
| 553 | idxe = -1 |
---|
| 554 | if idxb >= 0: |
---|
| 555 | if idxe < idxb + n_rows + 1: |
---|
| 556 | log.debug("Incoherent number of rows in coefficients") |
---|
| 557 | return False |
---|
| 558 | i = 0 |
---|
| 559 | for s in readMatrixString[idxb+1:idxb + n_rows + 1]: |
---|
| 560 | coeffs = s.split() |
---|
| 561 | if len(coeffs) < n_cols: |
---|
| 562 | log.debug("Incoherent number of columns in coefficients") |
---|
| 563 | return False |
---|
| 564 | j = 0 |
---|
| 565 | for c in coeffs[0:n_cols]: |
---|
| 566 | if transpose_coeff: |
---|
| 567 | self.interface.setValue(j, i, int(c)) |
---|
| 568 | else: |
---|
| 569 | self.interface.setValue(i, j, int(c)) |
---|
| 570 | j += 1 |
---|
| 571 | i += 1 |
---|
| 572 | del coeffs |
---|
| 573 | |
---|
| 574 | try: |
---|
| 575 | idxb = readMatrixString.index('<mutes>') |
---|
| 576 | idxe = readMatrixString.index('</mutes>') |
---|
| 577 | except Exception: |
---|
| 578 | log.debug("No mixer mute coefficients specified") |
---|
| 579 | idxb = -1 |
---|
| 580 | idxe = -1 |
---|
| 581 | if idxb >= 0: |
---|
| 582 | if idxe < idxb + n_rows + 1: |
---|
| 583 | log.debug("Incoherent number of rows in mute") |
---|
| 584 | return false |
---|
| 585 | i = 0 |
---|
| 586 | for s in readMatrixString[idxb+1:idxb + n_rows + 1]: |
---|
| 587 | coeffs = s.split() |
---|
| 588 | if len(coeffs) < n_cols: |
---|
| 589 | log.debug("Incoherent number of columns in mute") |
---|
| 590 | return false |
---|
| 591 | j = 0 |
---|
| 592 | for c in coeffs[0:n_cols]: |
---|
| 593 | if transpose_coeff: |
---|
| 594 | self.mutes_interface.setValue(j, i, int(c)) |
---|
| 595 | else: |
---|
| 596 | self.mutes_interface.setValue(i, j, int(c)) |
---|
| 597 | j += 1 |
---|
| 598 | i += 1 |
---|
| 599 | del coeffs |
---|
| 600 | |
---|
| 601 | try: |
---|
| 602 | idxb = readMatrixString.index('<inverts>') |
---|
| 603 | idxe = readMatrixString.index('</inverts>') |
---|
| 604 | except Exception: |
---|
| 605 | log.debug("No mixer inverts coefficients specified") |
---|
| 606 | idxb = -1 |
---|
| 607 | idxe = -1 |
---|
| 608 | if idxb >= 0: |
---|
| 609 | if idxe < idxb + n_rows + 1: |
---|
| 610 | log.debug("Incoherent number of rows in inverts") |
---|
| 611 | return false |
---|
| 612 | i = 0 |
---|
| 613 | for s in readMatrixString[idxb+1:idxb + n_rows + 1]: |
---|
| 614 | coeffs = s.split() |
---|
| 615 | if len(coeffs) < n_cols: |
---|
| 616 | log.debug("Incoherent number of columns in inverts") |
---|
| 617 | return false |
---|
| 618 | j = 0 |
---|
| 619 | for c in coeffs[0:n_cols]: |
---|
| 620 | if transpose_coeff: |
---|
| 621 | self.inverts_interface.setValue(j, i, int(c)) |
---|
| 622 | else: |
---|
| 623 | self.inverts_interface.setValue(i, j, int(c)) |
---|
| 624 | j += 1 |
---|
| 625 | i += 1 |
---|
| 626 | del coeffs |
---|
| 627 | |
---|
| 628 | self.refreshValues() |
---|
| 629 | return True |
---|
| 1011 | def saveSettings(self, indent): |
---|
| 1012 | rows = self.interface.getRowCount() |
---|
| 1013 | cols = self.interface.getColCount() |
---|
| 1014 | matrixSaveString = [] |
---|
| 1015 | matrixSaveString.append('%s <row_number>\n' % indent) |
---|
| 1016 | matrixSaveString.append('%s %d\n' % (indent, rows)) |
---|
| 1017 | matrixSaveString.append('%s </row_number>\n' % indent) |
---|
| 1018 | matrixSaveString.append('%s <col_number>\n' % indent) |
---|
| 1019 | matrixSaveString.append('%s %d\n' % (indent, cols)) |
---|
| 1020 | matrixSaveString.append('%s </col_number>\n' % indent) |
---|
| 1021 | matrixSaveString.append('%s <coefficients>\n' % indent) |
---|
| 1022 | for i in range(rows): |
---|
| 1023 | line = '%s ' % indent |
---|
| 1024 | for j in range(cols): |
---|
| 1025 | line += '%d ' % self.interface.getValue(i,j) |
---|
| 1026 | line += '\n' |
---|
| 1027 | matrixSaveString.append(line) |
---|
| 1028 | matrixSaveString.append('%s </coefficients>\n' % indent) |
---|
| 1029 | |
---|
| 1030 | return matrixSaveString |
---|
| 1031 | |
---|
| 1032 | def readSettings(self, readMatrixString, transpose_coeff): |
---|
| 1033 | rows = self.interface.getRowCount() |
---|
| 1034 | cols = self.interface.getColCount() |
---|
| 1035 | if readMatrixString[0].find("<row_number>") == -1: |
---|
| 1036 | log.debug("Number of matrix rows must be specified") |
---|
| 1037 | return False |
---|
| 1038 | if readMatrixString[2].find("</row_number>") == -1: |
---|
| 1039 | log.debug("Non-conformal xml file") |
---|
| 1040 | return False |
---|
| 1041 | n_rows = int(readMatrixString[1]) |
---|
| 1042 | |
---|
| 1043 | if readMatrixString[3].find("<col_number>") == -1: |
---|
| 1044 | log.debug("Number of matrix columns must be specified") |
---|
| 1045 | return False |
---|
| 1046 | if readMatrixString[5].find("</col_number>") == -1: |
---|
| 1047 | log.debug("Non-conformal xml file") |
---|
| 1048 | return False |
---|
| 1049 | n_cols = int(readMatrixString[4]) |
---|
| 1050 | |
---|
| 1051 | if transpose_coeff: |
---|
| 1052 | if n_rows > cols: |
---|
| 1053 | n_rows = cols |
---|
| 1054 | if n_cols > rows: |
---|
| 1055 | n_cols = rows |
---|
| 1056 | else: |
---|
| 1057 | if n_rows > rows: |
---|
| 1058 | n_rows = rows |
---|
| 1059 | if n_cols > cols: |
---|
| 1060 | n_cols = cols |
---|
| 1061 | log.debug("Setting %d rows and %d columns coefficients" % (n_rows, n_cols)) |
---|
| 1062 | |
---|
| 1063 | try: |
---|
| 1064 | idxb = readMatrixString.index('<coefficients>') |
---|
| 1065 | idxe = readMatrixString.index('</coefficients>') |
---|
| 1066 | except Exception: |
---|
| 1067 | log.debug("No mixer matrix coefficients specified") |
---|
| 1068 | idxb = -1 |
---|
| 1069 | idxe = -1 |
---|
| 1070 | if idxb >= 0: |
---|
| 1071 | if idxe < idxb + n_rows + 1: |
---|
| 1072 | log.debug("Incoherent number of rows in coefficients") |
---|
| 1073 | return False |
---|
| 1074 | i = 0 |
---|
| 1075 | for s in readMatrixString[idxb+1:idxb + n_rows + 1]: |
---|
| 1076 | coeffs = s.split() |
---|
| 1077 | if len(coeffs) < n_cols: |
---|
| 1078 | log.debug("Incoherent number of columns in coefficients") |
---|
| 1079 | return False |
---|
| 1080 | j = 0 |
---|
| 1081 | for c in coeffs[0:n_cols]: |
---|
| 1082 | if transpose_coeff: |
---|
| 1083 | self.interface.setValue(j, i, int(c)) |
---|
| 1084 | else: |
---|
| 1085 | self.interface.setValue(i, j, int(c)) |
---|
| 1086 | j += 1 |
---|
| 1087 | i += 1 |
---|
| 1088 | del coeffs |
---|
| 1089 | |
---|
| 1090 | self.refreshValues() |
---|
| 1091 | return True |
---|
| 1092 | |
---|
| 1388 | def saveSettings(self, indent): |
---|
| 1389 | mixerString = [] |
---|
| 1390 | mixerString.append("%s<matrices>\n" % indent) |
---|
| 1391 | mixerString.extend(self.matrix.saveSettings(indent)) |
---|
| 1392 | mixerString.append("%s</matrices>\n" % indent) |
---|
| 1393 | mixerString.append("%s<stereo_outputs>\n" % indent) |
---|
| 1394 | mixerString.append("%s <number>\n" % indent) |
---|
| 1395 | n = len(self.stereo_channels) |
---|
| 1396 | mixerString.append("%s %d\n" % (indent, n)) |
---|
| 1397 | mixerString.append("%s </number>\n" % indent) |
---|
| 1398 | if n > 0: |
---|
| 1399 | mixerString.append("%s <channels>\n" % indent) |
---|
| 1400 | for i in self.stereo_channels: |
---|
| 1401 | mixerString.append("%s %d %d\n" % (indent, i+1, i+2)) |
---|
| 1402 | mixerString.append("%s </channels>\n" % indent) |
---|
| 1403 | mixerString.append("%s</stereo_outputs>\n" % indent) |
---|
| 1404 | return mixerString |
---|
| 1405 | |
---|
| 1406 | def readSettings(self, readMixerString, transpose_coeff): |
---|
| 1407 | try: |
---|
| 1408 | idxb = readMixerString.index('<matrices>') |
---|
| 1409 | idxe = readMixerString.index('</matrices>') |
---|
| 1410 | except Exception: |
---|
| 1411 | log.debug("No matrices found") |
---|
| 1412 | idxb = -1 |
---|
| 1413 | idxe = -1 |
---|
| 1414 | if idxb >= 0: |
---|
| 1415 | if idxe > idxb+1: |
---|
| 1416 | readString = [] |
---|
| 1417 | for s in readMixerString[idxb+1:idxe]: |
---|
| 1418 | readString.append(s) |
---|
| 1419 | if self.matrix.readSettings(readString, transpose_coeff): |
---|
| 1420 | log.debug("Mixer matrices settings modified") |
---|
| 1421 | del readString |
---|
| 1422 | try: |
---|
| 1423 | idx = readMixerString.index('<stereo_outputs>') |
---|
| 1424 | except Exception: |
---|
| 1425 | log.debug("No stereo outputs channels information found") |
---|
| 1426 | idx = -1 |
---|
| 1427 | if idx >= 0: |
---|
| 1428 | if readMixerString[idx+1].find('<number>') == -1: |
---|
| 1429 | log.debug("Number of stereo output channels must be specified") |
---|
| 1430 | return False |
---|
| 1431 | n = int(readMixerString[idx+2]) |
---|
| 1432 | if n > self.perOut.nbOut/2: |
---|
| 1433 | log.debug("Incoherent number of stereo channels") |
---|
| 1434 | return False |
---|
| 1435 | if n > 0: |
---|
| 1436 | if readMixerString[idx+3].find('</number>') == -1: |
---|
| 1437 | log.debug("No </number> tag found") |
---|
| 1438 | return False |
---|
| 1439 | if readMixerString[idx+4].find('<channels>') == -1: |
---|
| 1440 | log.debug("No <channels> tag found") |
---|
| 1441 | return False |
---|
| 1442 | for s in readMixerString[idx+5:idx+5+n]: |
---|
| 1443 | i = (int(s.split()[0]) - 1)/2 |
---|
| 1444 | self.stereo_switch[i].setChecked(True); |
---|
| 1445 | self.switchStereoChannel(i, True) |
---|
| 1446 | return True |
---|
| 1447 | |
---|