1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
|
// -*- c-basic-offset: 4 -*-
/*
Rosegarden-4
A sequencer and musical notation editor.
This program is Copyright 2000-2005
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <bownie@bownie.com>
The moral right of the authors to claim authorship of this work
has been asserted.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include <qlayout.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qbuttongroup.h>
#include <qsignalmapper.h>
#include <qtooltip.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstddirs.h>
#include "trackbuttons.h"
#include "Track.h"
#include "Studio.h"
#include "colours.h"
#include "tracklabel.h"
#include "AudioPluginInstance.h"
#include "PluginIdentifier.h"
#include "AudioLevel.h"
#include "segmentcommands.h"
#include "rosestrings.h"
#include "rosedebug.h"
#include "rosegardenguidoc.h"
using Rosegarden::TrackId;
/**
* @author Stefan Schimanski
* Taken from KMix code,
* Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de>
*/
KLedButton::KLedButton(const QColor &col, QWidget *parent, const char *name)
: KLed( col, parent, name )
{
}
KLedButton::KLedButton(const QColor& col, KLed::State st, KLed::Look look,
KLed::Shape shape, QWidget *parent, const char *name)
: KLed( col, st, look, shape, parent, name )
{
}
KLedButton::~KLedButton()
{
}
void KLedButton::mousePressEvent( QMouseEvent *e )
{
if (e->button() == LeftButton)
{
toggle();
emit stateChanged( state() );
}
}
///////////////////////////////////////////////////////////
TrackVUMeter::TrackVUMeter(QWidget *parent,
VUMeterType type,
int width,
int height,
int position,
const char *name):
VUMeter(parent, type, false, width, height, VUMeter::Horizontal, name),
m_position(position), m_textHeight(12)
{
setAlignment(AlignCenter);
}
void
TrackVUMeter::meterStart()
{
clear();
setMinimumHeight(m_originalHeight);
setMaximumHeight(m_originalHeight);
}
void
TrackVUMeter::meterStop()
{
setMinimumHeight(m_textHeight);
setMaximumHeight(m_textHeight);
setText(QString("%1").arg(m_position + 1));
}
TrackButtons::TrackButtons(RosegardenGUIDoc* doc,
unsigned int trackCellHeight,
unsigned int trackLabelWidth,
bool showTrackLabels,
int overallHeight,
QWidget* parent,
const char* name,
WFlags f)
: QFrame(parent, name, f),
m_doc(doc),
m_layout(new QVBoxLayout(this)),
m_recordSigMapper(new QSignalMapper(this)),
m_muteSigMapper(new QSignalMapper(this)),
m_clickedSigMapper(new QSignalMapper(this)),
m_instListSigMapper(new QSignalMapper(this)),
m_tracks(doc->getComposition().getNbTracks()),
m_offset(4),
m_cellSize(trackCellHeight),
m_borderGap(1),
m_lastID(-1),
m_trackLabelWidth(trackLabelWidth),
m_popupItem(0),
m_lastSelected(-1)
{
setFrameStyle(Plain);
// when we create the widget, what are we looking at?
if (showTrackLabels)
m_trackInstrumentLabels = TrackLabel::ShowTrack;
else
m_trackInstrumentLabels = TrackLabel::ShowInstrument;
// Set the spacing between vertical elements
//
m_layout->setSpacing(m_borderGap);
// Now draw the buttons and labels and meters
//
makeButtons();
m_layout->addStretch(20);
connect(m_recordSigMapper, SIGNAL(mapped(int)),
this, SLOT(slotSetRecordTrack(int)));
connect(m_muteSigMapper, SIGNAL(mapped(int)),
this, SLOT(slotToggleMutedTrack(int)));
// connect signal mappers
connect(m_instListSigMapper, SIGNAL(mapped(int)),
this, SLOT(slotInstrumentSelection(int)));
connect(m_clickedSigMapper, SIGNAL(mapped(int)),
this, SIGNAL(trackSelected(int)));
// // Populate instrument popup menu just once at start-up
// //
// populateInstrumentPopup();
// We have to force the height for the moment
//
setMinimumHeight(overallHeight);
}
TrackButtons::~TrackButtons()
{
}
// Draw the mute and record buttons, track labels and VU meters
//
void
TrackButtons::makeButtons()
{
if (!m_doc) return;
// Create a horizontal box for each track
// plus the two buttons
//
unsigned int nbTracks = m_doc->getComposition().getNbTracks();
for (unsigned int i = 0; i < nbTracks; ++i)
{
Rosegarden::Track *track = m_doc->getComposition().getTrackByPosition(i);
if (track)
{
QFrame *trackHBox = makeButton(track->getId());
if (trackHBox)
{
m_layout->addWidget(trackHBox);
m_trackHBoxes.push_back(trackHBox);
}
}
}
populateButtons();
}
QFrame* TrackButtons::makeButton(Rosegarden::TrackId trackId)
{
// The buttonGap sets up the sizes of the buttons
//
static const int buttonGap = 8;
QFrame *trackHBox = 0;
KLedButton *mute = 0;
KLedButton *record = 0;
TrackVUMeter *vuMeter = 0;
TrackLabel *trackLabel = 0;
int vuWidth = 20;
int vuSpacing = 2;
int labelWidth = m_trackLabelWidth - ( (m_cellSize - buttonGap) * 2 +
vuSpacing * 2 + vuWidth );
// Set the label from the Track object on the Composition
//
Rosegarden::Track *track = m_doc->getComposition().getTrackById(trackId);
if (track == 0) return 0;
// Create a horizontal box for each track
//
trackHBox = new QFrame(this);
QHBoxLayout *hblayout = new QHBoxLayout(trackHBox);
trackHBox->setMinimumSize(labelWidth, m_cellSize - m_borderGap);
trackHBox->setFixedHeight(m_cellSize - m_borderGap);
// Try a style for the box
//
trackHBox->setFrameStyle(StyledPanel);
trackHBox->setFrameShape(StyledPanel);
trackHBox->setFrameShadow(Raised);
// Insert a little gap
hblayout->addSpacing(vuSpacing);
// Create a VU meter
vuMeter = new TrackVUMeter(trackHBox,
VUMeter::PeakHold,
vuWidth,
buttonGap,
track->getPosition());
m_trackMeters.push_back(vuMeter);
hblayout->addWidget(vuMeter);
// Create another little gap
hblayout->addSpacing(vuSpacing);
//
// 'mute' and 'record' leds
//
mute = new KLedButton(Rosegarden::GUIPalette::getColour(Rosegarden::GUIPalette::MuteTrackLED), trackHBox);
QToolTip::add(mute, i18n("Mute track"));
hblayout->addWidget(mute);
record = new KLedButton(Rosegarden::GUIPalette::getColour(Rosegarden::GUIPalette::RecordTrackLED), trackHBox);
QToolTip::add(record, i18n("Record on this track"));
hblayout->addWidget(record);
record->setLook(KLed::Sunken);
mute->setLook(KLed::Sunken);
record->off();
// Connect them to their sigmappers
connect(record, SIGNAL(stateChanged(bool)),
m_recordSigMapper, SLOT(map()));
connect(mute, SIGNAL(stateChanged(bool)),
m_muteSigMapper, SLOT(map()));
m_recordSigMapper->setMapping(record, track->getPosition());
m_muteSigMapper->setMapping(mute, track->getPosition());
// Store the KLedButton
//
m_muteLeds.push_back(mute);
m_recordLeds.push_back(record);
//
// Track label
//
trackLabel = new TrackLabel(trackId, track->getPosition(), trackHBox);
hblayout->addWidget(trackLabel);
if (track->getLabel() == std::string("")) {
Rosegarden::Instrument *ins =
m_doc->getStudio().getInstrumentById(track->getInstrument());
if (ins && ins->getType() == Rosegarden::Instrument::Audio) {
trackLabel->getTrackLabel()->setText(i18n("<untitled audio>"));
} else {
trackLabel->getTrackLabel()->setText(i18n("<untitled>"));
}
}
else
trackLabel->getTrackLabel()->setText(strtoqstr(track->getLabel()));
trackLabel->setFixedSize(labelWidth, m_cellSize - buttonGap);
trackLabel->setFixedHeight(m_cellSize - buttonGap);
trackLabel->setIndent(7);
connect(trackLabel, SIGNAL(renameTrack(QString, Rosegarden::TrackId)),
SLOT(slotRenameTrack(QString, Rosegarden::TrackId)));
// Store the TrackLabel pointer
//
m_trackLabels.push_back(trackLabel);
// Connect it
setButtonMapping(trackLabel, trackId);
connect(trackLabel, SIGNAL(changeToInstrumentList()),
m_instListSigMapper, SLOT(map()));
connect(trackLabel, SIGNAL(clicked()),
m_clickedSigMapper, SLOT(map()));
//
// instrument label
//
Rosegarden::Instrument *ins =
m_doc->getStudio().getInstrumentById(track->getInstrument());
QString instrumentName(i18n("<no instrument>"));
if (ins) instrumentName = strtoqstr(ins->getPresentationName());
// Set label to program change if it's being sent
//
if (ins != 0 && ins->sendsProgramChange())
trackLabel->setAlternativeLabel(strtoqstr(ins->getProgramName()));
trackLabel->showLabel(m_trackInstrumentLabels);
mute->setFixedSize(m_cellSize - buttonGap, m_cellSize - buttonGap);
record->setFixedSize(m_cellSize - buttonGap, m_cellSize - buttonGap);
// set the mute button
//
if (track->isMuted())
mute->off();
return trackHBox;
}
void TrackButtons::setButtonMapping(QObject* obj, Rosegarden::TrackId trackId)
{
m_clickedSigMapper->setMapping(obj, trackId);
m_instListSigMapper->setMapping(obj, trackId);
}
// Return the track that's currently set for recording
//
//
int TrackButtons::selectedRecordTrack()
{
return m_lastID;
}
// Fill out the buttons with Instrument information
//
void
TrackButtons::populateButtons()
{
Rosegarden::Instrument *ins = 0;
Rosegarden::Track *track;
for (unsigned int i = 0; i < m_trackLabels.size(); ++i)
{
track = m_doc->getComposition().getTrackByPosition(i);
if (track)
{
ins = m_doc->getStudio().getInstrumentById(track->getInstrument());
// Set mute button from track
//
if (track->isMuted())
m_muteLeds[i]->off();
else
m_muteLeds[i]->on();
// Set record button from track
//
if (m_doc->getComposition().getRecordTrack() == track->getId())
setRecordTrack(track->getPosition());
// reset track tokens
m_trackLabels[i]->setId(track->getId());
setButtonMapping(m_trackLabels[i], track->getId());
m_trackLabels[i]->setPosition(i);
}
if (ins)
{
m_trackLabels[i]->getInstrumentLabel()->setText
(strtoqstr(ins->getPresentationName()));
if (ins->sendsProgramChange())
{
m_trackLabels[i]->setAlternativeLabel(strtoqstr(ins->getProgramName()));
}
}
else
{
m_trackLabels[i]->getInstrumentLabel()->setText(i18n("<no instrument>"));
}
m_trackLabels[i]->update();
}
}
// Create and return a vector of all muted tracks
//
//
std::vector<int>
TrackButtons::mutedTracks()
{
std::vector<int> mutedTracks;
for (TrackId i = 0; i < m_tracks; i++)
{
if (m_muteLeds[i]->state() == KLed::Off)
mutedTracks.push_back(i);
}
return mutedTracks;
}
// Toggle a mute button
//
//
void
TrackButtons::slotToggleMutedTrack(int mutedTrackPos)
{
RG_DEBUG << "TrackButtons::slotToggleMutedTrack(" << mutedTrackPos << ")\n";
if (mutedTrackPos < 0 || mutedTrackPos > (int)m_tracks )
return;
Rosegarden::Track *track =
m_doc->getComposition().getTrackByPosition(mutedTrackPos);
emit muteButton(track->getId(), !track->isMuted()); // will set the value
}
// Remove buttons from all iterators and delete object
//
void
TrackButtons::removeButtons(unsigned int position)
{
RG_DEBUG << "TrackButtons::removeButtons - "
<< "deleting track button at position "
<< position << endl;
if (position >= m_trackHBoxes.size()) {
RG_DEBUG << "%%%%%%%%% BIG PROBLEM : TrackButtons::removeButtons() was passed a non-existing index\n";
return;
}
std::vector<TrackLabel*>::iterator tit = m_trackLabels.begin();
tit += position;
m_trackLabels.erase(tit);
std::vector<TrackVUMeter*>::iterator vit = m_trackMeters.begin();
vit += position;
m_trackMeters.erase(vit);
std::vector<KLedButton*>::iterator mit = m_muteLeds.begin();
mit += position;
m_muteLeds.erase(mit);
mit = m_recordLeds.begin();
mit += position;
m_recordLeds.erase(mit);
delete m_trackHBoxes[position]; // deletes all child widgets (button, led, label...)
std::vector<QFrame*>::iterator it = m_trackHBoxes.begin();
it += position;
m_trackHBoxes.erase(it);
}
void
TrackButtons::slotUpdateTracks()
{
Rosegarden::Composition &comp = m_doc->getComposition();
unsigned int newNbTracks = comp.getNbTracks();
Rosegarden::Track *track = 0;
track = comp.getTrackById(comp.getRecordTrack());
if (track)
setRecordTrack(track->getPosition());
if (newNbTracks < m_tracks)
{
for (unsigned int i = m_tracks; i > newNbTracks; --i)
removeButtons(i - 1);
}
else if (newNbTracks > m_tracks)
{
for (unsigned int i = m_tracks; i < newNbTracks; ++i)
{
track = m_doc->getComposition().getTrackByPosition(i);
if (track)
{
QFrame *trackHBox = makeButton(track->getId());
if (trackHBox)
{
trackHBox->show();
m_layout->insertWidget(i, trackHBox);
m_trackHBoxes.push_back(trackHBox);
}
}
else
RG_DEBUG << "TrackButtons::slotUpdateTracks - can't find TrackId for position " << i << endl;
}
}
// Renumber all the labels
//
for (unsigned int i = 0; i < m_trackLabels.size(); ++i)
{
track = comp.getTrackByPosition(i);
if (track) {
m_trackLabels[i]->setId(track->getId());
QLabel *trackLabel = m_trackLabels[i]->getTrackLabel();
if (track->getLabel() == std::string("")) {
Rosegarden::Instrument *ins =
m_doc->getStudio().getInstrumentById(track->getInstrument());
if (ins && ins->getType() == Rosegarden::Instrument::Audio) {
trackLabel->setText(i18n("<untitled audio>"));
} else {
trackLabel->setText(i18n("<untitled>"));
}
}
else {
trackLabel->setText(strtoqstr(track->getLabel()));
}
// RG_DEBUG << "TrackButtons::slotUpdateTracks - set button mapping at pos "
// << i << " to track id " << track->getId() << endl;
setButtonMapping(m_trackLabels[i], track->getId());
}
}
m_tracks = newNbTracks;
// repopulate the buttons
populateButtons();
}
// Set a newly selected record button to a shocking palette and
// unset the palette on the record buttons we're jumping from.
//
//
void
TrackButtons::slotSetRecordTrack(int position)
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Track *track = comp.getTrackByPosition(position);
setRecordTrack(position);
selectLabel(position);
comp.setSelectedTrack(track->getId());
emit newRecordButton();
}
void
TrackButtons::setRecordTrack(int position)
{
setRecordButtonDown(position);
// set and update
m_doc->getComposition().setRecordTrack(m_trackLabels[position]->getId());
}
void
TrackButtons::setRecordButtonDown(int position)
{
if (position < 0 || position >= (int)m_tracks)
return;
KLedButton* led = m_recordLeds[position];
led->on();
if (m_lastID != position && m_lastID != -1) {
m_recordLeds[m_lastID]->off();
}
m_lastID = position;
}
void
TrackButtons::selectLabel(int position)
{
if (m_lastSelected >= 0 && m_lastSelected < m_trackLabels.size()) {
m_trackLabels[m_lastSelected]->setSelected(false);
}
if (position >= 0 && position < m_trackLabels.size()) {
m_trackLabels[position]->setSelected(true);
m_lastSelected = position;
}
}
// Return a vector of highlighted tracks by querying the TrackLabels
// for highlight state.
//
std::vector<int>
TrackButtons::getHighlightedTracks()
{
std::vector<int> retList;
for (unsigned int i = 0; i < m_trackLabels.size(); ++i)
{
if (m_trackLabels[i]->isSelected())
retList.push_back(i);
}
return retList;
}
void
TrackButtons::slotRenameTrack(QString newName, Rosegarden::TrackId trackId)
{
m_doc->getCommandHistory()->addCommand
(new RenameTrackCommand(&m_doc->getComposition(),
trackId,
qstrtostr(newName)));
changeTrackLabel(trackId, newName);
}
void
TrackButtons::slotSetTrackMeter(float value, int position)
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
Rosegarden::Track *track;
for (unsigned int i = 0; i < m_trackMeters.size(); ++i)
{
if (i == ((unsigned int)position))
{
m_trackMeters[i]->setLevel(value);
return;
}
}
}
// For all Track meters get their position and from that
// value work out their Track and hence Instrument and
// equate that to the Instrument we're setting.
//
void
TrackButtons::slotSetMetersByInstrument(float value,
Rosegarden::InstrumentId id)
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
Rosegarden::Track *track;
for (unsigned int i = 0; i < m_trackMeters.size(); ++i)
{
track = comp.getTrackByPosition(i);
if (track != 0 && track->getInstrument() == id)
{
m_trackMeters[i]->setLevel(value);
}
}
}
void
TrackButtons::slotInstrumentSelection(int trackId)
{
RG_DEBUG << "TrackButtons::slotInstrumentSelection(" << trackId << ")\n";
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
int position = comp.getTrackById(trackId)->getPosition();
QString instrumentName = i18n("<no instrument>");
Rosegarden::Track *track = comp.getTrackByPosition(position);
Rosegarden::Instrument *instrument = 0;
if (track != 0) {
instrument = studio.getInstrumentById(track->getInstrument());
if (instrument)
instrumentName = strtoqstr(instrument->getPresentationName());
}
//
// populate this instrument widget
m_trackLabels[position]->getInstrumentLabel()->setText(instrumentName);
// Ensure the instrument name is shown
m_trackLabels[position]->showLabel(TrackLabel::ShowInstrument);
// Yes, well as we might've changed the Device name in the
// Device/Bank dialog then we reload the whole menu here.
//
QPopupMenu instrumentPopup(this);
populateInstrumentPopup(instrument, &instrumentPopup);
// Store the popup item position
//
m_popupItem = position;
instrumentPopup.exec(QCursor::pos());
// Restore the label back to what it was showing
m_trackLabels[position]->showLabel(m_trackInstrumentLabels);
}
void
TrackButtons::populateInstrumentPopup(Rosegarden::Instrument *thisTrackInstr, QPopupMenu* instrumentPopup)
{
static QPixmap connectedPixmap, unconnectedPixmap,
connectedUsedPixmap, unconnectedUsedPixmap,
connectedSelectedPixmap, unconnectedSelectedPixmap;
static bool havePixmaps = false;
if (!havePixmaps) {
QString pixmapDir =
KGlobal::dirs()->findResource("appdata", "pixmaps/");
connectedPixmap.load
(QString("%1/misc/connected.xpm").arg(pixmapDir));
connectedUsedPixmap.load
(QString("%1/misc/connected-used.xpm").arg(pixmapDir));
connectedSelectedPixmap.load
(QString("%1/misc/connected-selected.xpm").arg(pixmapDir));
unconnectedPixmap.load
(QString("%1/misc/unconnected.xpm").arg(pixmapDir));
unconnectedUsedPixmap.load
(QString("%1/misc/unconnected-used.xpm").arg(pixmapDir));
unconnectedSelectedPixmap.load
(QString("%1/misc/unconnected-selected.xpm").arg(pixmapDir));
havePixmaps = true;
}
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
// clear the popup
instrumentPopup->clear();
std::vector<QPopupMenu*> instrumentSubMenus;
// position index
int i = 0;
// Get the list
Rosegarden::InstrumentList list = studio.getPresentationInstruments();
Rosegarden::InstrumentList::iterator it;
int currentDevId = -1;
bool deviceUsedByAnyone = false;
for (it = list.begin(); it != list.end(); it++) {
if (! (*it)) continue; // sanity check
QString iname(strtoqstr((*it)->getPresentationName()));
QString pname(strtoqstr((*it)->getProgramName()));
Rosegarden::Device *device = (*it)->getDevice();
Rosegarden::DeviceId devId = device->getId();
bool connected = false;
if ((*it)->getType() == Rosegarden::Instrument::SoftSynth) {
pname = "";
Rosegarden::AudioPluginInstance *plugin = (*it)->getPlugin
(Rosegarden::Instrument::SYNTH_PLUGIN_POSITION);
if (plugin) {
pname = strtoqstr(plugin->getProgram());
QString identifier = strtoqstr(plugin->getIdentifier());
if (identifier != "") {
connected = true;
QString type, soName, label;
Rosegarden::PluginIdentifier::parseIdentifier
(identifier, type, soName, label);
if (pname == "") {
pname = strtoqstr(plugin->getDistinctiveConfigurationText());
}
if (pname != "") {
pname = QString("%1: %2").arg(label).arg(pname);
} else {
pname = label;
}
} else {
connected = false;
}
}
} else if ((*it)->getType() == Rosegarden::Instrument::Audio) {
connected = true;
} else {
connected = (device->getConnection() != "");
}
bool instrUsedByMe = false;
bool instrUsedByAnyone = false;
if (thisTrackInstr && thisTrackInstr->getId() == (*it)->getId()) {
instrUsedByMe = true;
instrUsedByAnyone = true;
}
if (devId != (Rosegarden::DeviceId)(currentDevId)) {
deviceUsedByAnyone = false;
if (instrUsedByMe) deviceUsedByAnyone = true;
else {
for (Rosegarden::Composition::trackcontainer::iterator tit =
comp.getTracks().begin();
tit != comp.getTracks().end(); ++tit) {
if (tit->second->getInstrument() == (*it)->getId()) {
instrUsedByAnyone = true;
deviceUsedByAnyone = true;
break;
}
Rosegarden::Instrument *instr =
studio.getInstrumentById(tit->second->getInstrument());
if (instr && (instr->getDevice()->getId() == devId)) {
deviceUsedByAnyone = true;
}
}
}
QIconSet iconSet
(connected ?
(deviceUsedByAnyone ?
connectedUsedPixmap : connectedPixmap) :
(deviceUsedByAnyone ?
unconnectedUsedPixmap : unconnectedPixmap));
currentDevId = int(devId);
QPopupMenu *subMenu = new QPopupMenu(instrumentPopup);
QString deviceName = strtoqstr(device->getName());
instrumentPopup->insertItem(iconSet, deviceName, subMenu);
instrumentSubMenus.push_back(subMenu);
// Connect up the submenu
//
connect(subMenu, SIGNAL(activated(int)),
SLOT(slotInstrumentPopupActivated(int)));
} else if (!instrUsedByMe) {
for (Rosegarden::Composition::trackcontainer::iterator tit =
comp.getTracks().begin();
tit != comp.getTracks().end(); ++tit) {
if (tit->second->getInstrument() == (*it)->getId()) {
instrUsedByAnyone = true;
break;
}
}
}
QIconSet iconSet
(connected ?
(instrUsedByAnyone ?
instrUsedByMe ?
connectedSelectedPixmap :
connectedUsedPixmap : connectedPixmap) :
(instrUsedByAnyone ?
instrUsedByMe ?
unconnectedSelectedPixmap :
unconnectedUsedPixmap : unconnectedPixmap));
if (pname != "") iname += " (" + pname + ")";
instrumentSubMenus[instrumentSubMenus.size() - 1]->insertItem(iconSet, iname, i++);
}
}
// Set the relevant Instrument for the Track
// according to popup position.
//
void
TrackButtons::slotInstrumentPopupActivated(int item)
{
RG_DEBUG << "TrackButtons::slotInstrumentPopupActivated " << item << endl;
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
Rosegarden::Instrument *inst = studio.getInstrumentFromList(item);
RG_DEBUG << "TrackButtons::slotInstrumentPopupActivated: instrument " << inst << endl;
if (inst != 0)
{
Rosegarden::Track *track = comp.getTrackByPosition(m_popupItem);
if (track != 0)
{
track->setInstrument(inst->getId());
// select instrument
emit instrumentSelected((int)inst->getId());
m_trackLabels[m_popupItem]->getInstrumentLabel()->
setText(strtoqstr(inst->getPresentationName()));
// reset the alternative label
m_trackLabels[m_popupItem]->clearAlternativeLabel();
// Now see if the program is being shown for this instrument
// and if so reset the label
//
if (inst->sendsProgramChange())
m_trackLabels[m_popupItem]->setAlternativeLabel(strtoqstr(inst->getProgramName()));
// Ensure that we set a record track properly
//
if (track->getId() == comp.getRecordTrack())
slotSetRecordTrack(track->getPosition());
}
else
RG_DEBUG << "slotInstrumentPopupActivated() - can't find item!\n";
}
else
RG_DEBUG << "slotInstrumentPopupActivated() - can't find item!\n";
}
// Hide and show Tracks and Instruments
//
void
TrackButtons::changeTrackInstrumentLabels(TrackLabel::InstrumentTrackLabels label)
{
// Set new label
m_trackInstrumentLabels = label;
// update and reconnect with new value
for (int i = 0; i < (int)m_tracks; i++) {
m_trackLabels[i]->showLabel(label);
}
}
// Set all the labels that are showing InstrumentId to show a
// new label - this is usually driven by enabling program change
// sending for this instrument
//
void
TrackButtons::changeInstrumentLabel(Rosegarden::InstrumentId id, QString label)
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Track *track;
for (int i = 0; i < (int)m_tracks; i++)
{
track = comp.getTrackByPosition(i);
if(track && track->getInstrument() == id)
m_trackLabels[i]->setAlternativeLabel(label);
}
}
void
TrackButtons::changeTrackLabel(Rosegarden::TrackId id, QString label)
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Track *track;
for (int i = 0; i < (int)m_tracks; i++)
{
track = comp.getTrackByPosition(i);
if (track && track->getId() == id) {
if (m_trackLabels[i]->getTrackLabel()->text() != label) {
m_trackLabels[i]->getTrackLabel()->setText(label);
emit widthChanged();
emit nameChanged();
}
return;
}
}
}
void
TrackButtons::slotSynchroniseWithComposition()
{
Rosegarden::Composition &comp = m_doc->getComposition();
Rosegarden::Studio &studio = m_doc->getStudio();
Rosegarden::Track *track;
for (int i = 0; i < (int)m_tracks; i++)
{
track = comp.getTrackByPosition(i);
if (track)
{
if (track->isMuted())
m_muteLeds[i]->off();
else
m_muteLeds[i]->on();
Rosegarden::Instrument *ins = studio.
getInstrumentById(track->getInstrument());
QString instrumentName(i18n("<no instrument>"));
if (ins) instrumentName = strtoqstr(ins->getPresentationName());
m_trackLabels[i]->getInstrumentLabel()->setText(instrumentName);
}
}
setRecordButtonDown(comp.getRecordTrack());
}
void
TrackButtons::slotLabelSelected(int position)
{
Rosegarden::Track *track =
m_doc->getComposition().getTrackByPosition(position);
if (track)
{
emit trackSelected(track->getId());
}
}
// Set a mute button to a particular state
void
TrackButtons::setMuteButton(TrackId track, bool value)
{
Rosegarden::Track *trackObj = m_doc->getComposition().getTrackById(track);
if (trackObj == 0) return;
int pos = trackObj->getPosition();
RG_DEBUG << "TrackButtons::setMuteButton() trackId = "
<< track << ", pos = " << pos << endl;
m_muteLeds[pos]->setState(value ? KLed::Off : KLed::On);
}
|