PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/rosegarden-12.04/src/gui/seqmanager/MidiFilterDialog.cpp

#
C++ | 324 lines | 230 code | 69 blank | 25 comment | 34 complexity | 4a610a3e34fc212249785ccd1083b156 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
  2. /*
  3. Rosegarden
  4. A MIDI and audio sequencer and musical notation editor.
  5. Copyright 2000-2012 the Rosegarden development team.
  6. Other copyrights also apply to some parts of this work. Please
  7. see the AUTHORS file and individual file headers for details.
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version. See the file
  12. COPYING included with this distribution for more information.
  13. */
  14. #include "MidiFilterDialog.h"
  15. #include "base/MidiProgram.h"
  16. #include "base/NotationTypes.h"
  17. #include "document/RosegardenDocument.h"
  18. #include "gui/seqmanager/SequenceManager.h"
  19. #include "sound/MappedEvent.h"
  20. #include <QDialog>
  21. #include <QDialogButtonBox>
  22. #include <QPushButton>
  23. #include <QGroupBox>
  24. #include <QCheckBox>
  25. #include <QWidget>
  26. #include <QHBoxLayout>
  27. #include <QVBoxLayout>
  28. #include <QUrl>
  29. #include <QDesktopServices>
  30. namespace Rosegarden
  31. {
  32. MidiFilterDialog::MidiFilterDialog(QWidget *parent,
  33. RosegardenDocument *doc):
  34. QDialog(parent),
  35. m_doc(doc),
  36. m_modified(true),
  37. m_buttonBox(0)
  38. {
  39. //setHelp("studio-midi-filters");
  40. setModal(true);
  41. setWindowTitle(tr("Modify MIDI filters..."));
  42. QGridLayout *metagrid = new QGridLayout;
  43. setLayout(metagrid);
  44. QWidget *hBox = new QWidget(this);
  45. QHBoxLayout *hBoxLayout = new QHBoxLayout;
  46. metagrid->addWidget(hBox, 0, 0);
  47. m_thruBox = new QGroupBox(
  48. tr("THRU events to ignore"), hBox );
  49. QVBoxLayout *thruBoxLayout = new QVBoxLayout;
  50. hBoxLayout->addWidget(m_thruBox);
  51. QCheckBox *noteThru = new QCheckBox(tr("Note"), m_thruBox);
  52. QCheckBox *progThru = new QCheckBox(tr("Program Change"), m_thruBox);
  53. QCheckBox *keyThru = new QCheckBox(tr("Key Pressure"), m_thruBox);
  54. QCheckBox *chanThru = new QCheckBox(tr("Channel Pressure"), m_thruBox);
  55. QCheckBox *pitchThru = new QCheckBox(tr("Pitch Bend"), m_thruBox);
  56. QCheckBox *contThru = new QCheckBox(tr("Controller"), m_thruBox);
  57. QCheckBox *sysThru = new QCheckBox(tr("System Exclusive"), m_thruBox);
  58. noteThru->setObjectName("Note");
  59. progThru->setObjectName("Program Change");
  60. keyThru->setObjectName("Key Pressure");
  61. chanThru->setObjectName("Channel Pressure");
  62. pitchThru->setObjectName("Pitch Bend");
  63. contThru->setObjectName("Controller");
  64. sysThru->setObjectName("System Exclusive");
  65. thruBoxLayout->addWidget(noteThru);
  66. thruBoxLayout->addWidget(progThru);
  67. thruBoxLayout->addWidget(keyThru);
  68. thruBoxLayout->addWidget(chanThru);
  69. thruBoxLayout->addWidget(pitchThru);
  70. thruBoxLayout->addWidget(contThru);
  71. thruBoxLayout->addWidget(sysThru);
  72. m_thruBox->setLayout(thruBoxLayout);
  73. MidiFilter thruFilter = m_doc->getStudio().getMIDIThruFilter();
  74. if (thruFilter & MappedEvent::MidiNote)
  75. noteThru->setChecked(true);
  76. if (thruFilter & MappedEvent::MidiProgramChange)
  77. progThru->setChecked(true);
  78. if (thruFilter & MappedEvent::MidiKeyPressure)
  79. keyThru->setChecked(true);
  80. if (thruFilter & MappedEvent::MidiChannelPressure)
  81. chanThru->setChecked(true);
  82. if (thruFilter & MappedEvent::MidiPitchBend)
  83. pitchThru->setChecked(true);
  84. if (thruFilter & MappedEvent::MidiController)
  85. contThru->setChecked(true);
  86. if (thruFilter & MappedEvent::MidiSystemMessage)
  87. sysThru->setChecked(true);
  88. m_recordBox = new QGroupBox(
  89. tr("RECORD events to ignore"), hBox );
  90. QVBoxLayout *recordBoxLayout = new QVBoxLayout;
  91. hBoxLayout->addWidget(m_recordBox);
  92. QCheckBox *noteRecord = new QCheckBox(tr("Note"), m_recordBox);
  93. QCheckBox *progRecord = new QCheckBox(tr("Program Change"), m_recordBox);
  94. QCheckBox *keyRecord = new QCheckBox(tr("Key Pressure"), m_recordBox);
  95. QCheckBox *chanRecord = new QCheckBox(tr("Channel Pressure"), m_recordBox);
  96. QCheckBox *pitchRecord = new QCheckBox(tr("Pitch Bend"), m_recordBox);
  97. QCheckBox *contRecord = new QCheckBox(tr("Controller"), m_recordBox);
  98. QCheckBox *sysRecord = new QCheckBox(tr("System Exclusive"), m_recordBox);
  99. noteRecord->setObjectName("Note");
  100. progRecord->setObjectName("Program Change");
  101. keyRecord->setObjectName("Key Pressure");
  102. chanRecord->setObjectName("Channel Pressure");
  103. pitchRecord->setObjectName("Pitch Bend");
  104. contRecord->setObjectName("Controller");
  105. sysRecord->setObjectName("System Exclusive");
  106. recordBoxLayout->addWidget(noteRecord);
  107. recordBoxLayout->addWidget(progRecord);
  108. recordBoxLayout->addWidget(keyRecord);
  109. recordBoxLayout->addWidget(chanRecord);
  110. recordBoxLayout->addWidget(pitchRecord);
  111. recordBoxLayout->addWidget(contRecord);
  112. recordBoxLayout->addWidget(sysRecord);
  113. m_recordBox->setLayout(recordBoxLayout);
  114. MidiFilter recordFilter =
  115. m_doc->getStudio().getMIDIRecordFilter();
  116. if (recordFilter & MappedEvent::MidiNote)
  117. noteRecord->setChecked(true);
  118. if (recordFilter & MappedEvent::MidiProgramChange)
  119. progRecord->setChecked(true);
  120. if (recordFilter & MappedEvent::MidiKeyPressure)
  121. keyRecord->setChecked(true);
  122. if (recordFilter & MappedEvent::MidiChannelPressure)
  123. chanRecord->setChecked(true);
  124. if (recordFilter & MappedEvent::MidiPitchBend)
  125. pitchRecord->setChecked(true);
  126. if (recordFilter & MappedEvent::MidiController)
  127. contRecord->setChecked(true);
  128. if (recordFilter & MappedEvent::MidiSystemMessage)
  129. sysRecord->setChecked(true);
  130. hBox->setLayout(hBoxLayout);
  131. m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
  132. QDialogButtonBox::Apply |
  133. QDialogButtonBox::Close |
  134. QDialogButtonBox::Help);
  135. metagrid->addWidget(m_buttonBox, 1, 0);
  136. metagrid->setRowStretch(0, 10);
  137. connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  138. connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  139. connect(m_buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
  140. m_applyButton = m_buttonBox->button(QDialogButtonBox::Apply);
  141. connect(m_applyButton, SIGNAL(clicked()), this, SLOT(slotApply()));
  142. // changing the state of any checkbox sets modified true
  143. connect(noteThru, SIGNAL(stateChanged(int)),
  144. SLOT(slotSetModified(int)));
  145. connect(progThru, SIGNAL(stateChanged(int)),
  146. SLOT(slotSetModified(int)));
  147. connect(keyThru, SIGNAL(stateChanged(int)),
  148. SLOT(slotSetModified(int)));
  149. connect(chanThru, SIGNAL(stateChanged(int)),
  150. SLOT(slotSetModified(int)));
  151. connect(pitchThru, SIGNAL(stateChanged(int)),
  152. SLOT(slotSetModified(int)));
  153. connect(contThru, SIGNAL(stateChanged(int)),
  154. SLOT(slotSetModified(int)));
  155. connect(sysThru, SIGNAL(stateChanged(int)),
  156. SLOT(slotSetModified(int)));
  157. connect(noteRecord, SIGNAL(stateChanged(int)),
  158. SLOT(slotSetModified(int)));
  159. connect(progRecord, SIGNAL(stateChanged(int)),
  160. SLOT(slotSetModified(int)));
  161. connect(keyRecord, SIGNAL(stateChanged(int)),
  162. SLOT(slotSetModified(int)));
  163. connect(chanRecord, SIGNAL(stateChanged(int)),
  164. SLOT(slotSetModified(int)));
  165. connect(pitchRecord, SIGNAL(stateChanged(int)),
  166. SLOT(slotSetModified(int)));
  167. connect(contRecord, SIGNAL(stateChanged(int)),
  168. SLOT(slotSetModified(int)));
  169. connect(sysRecord, SIGNAL(stateChanged(int)),
  170. SLOT(slotSetModified(int)));
  171. // setting the thing up initially changes states and trips signals, so we
  172. // have to do this to wipe the slate clean initially after all the false
  173. // positives
  174. setModified(false);
  175. }
  176. void
  177. MidiFilterDialog::help()
  178. {
  179. // TRANSLATORS: if the manual is translated into your language, you can
  180. // change the two-letter language code in this URL to point to your language
  181. // version, eg. "http://rosegardenmusic.com/wiki/doc:manual-es" for the
  182. // Spanish version. If your language doesn't yet have a translation, feel
  183. // free to create one.
  184. QString helpURL = tr("http://rosegardenmusic.com/wiki/doc:midi-filter-en");
  185. QDesktopServices::openUrl(QUrl(helpURL));
  186. }
  187. void
  188. MidiFilterDialog::slotApply()
  189. {
  190. std::cerr << "MidiFilterDialog::slotApply()" << std::endl;
  191. MidiFilter thruFilter = 0,
  192. recordFilter = 0;
  193. if (m_thruBox->findChild<QCheckBox*>("Note")->isChecked())
  194. thruFilter |= MappedEvent::MidiNote;
  195. if (m_thruBox->findChild<QCheckBox*>("Program Change")->isChecked())
  196. thruFilter |= MappedEvent::MidiProgramChange;
  197. if (m_thruBox->findChild<QCheckBox*>("Key Pressure")->isChecked())
  198. thruFilter |= MappedEvent::MidiKeyPressure;
  199. if (m_thruBox->findChild<QCheckBox*>("Channel Pressure")->isChecked())
  200. thruFilter |= MappedEvent::MidiChannelPressure;
  201. if (m_thruBox->findChild<QCheckBox*>("Pitch Bend")->isChecked())
  202. thruFilter |= MappedEvent::MidiPitchBend;
  203. if (m_thruBox->findChild<QCheckBox*>("Controller")->isChecked())
  204. thruFilter |= MappedEvent::MidiController;
  205. if (m_thruBox->findChild<QCheckBox*>("System Exclusive")->isChecked())
  206. thruFilter |= MappedEvent::MidiSystemMessage;
  207. if (m_recordBox->findChild<QCheckBox*>("Note")->isChecked())
  208. recordFilter |= MappedEvent::MidiNote;
  209. if (m_recordBox->findChild<QCheckBox*>("Program Change")->isChecked())
  210. recordFilter |= MappedEvent::MidiProgramChange;
  211. if (m_recordBox->findChild<QCheckBox*>("Key Pressure")->isChecked())
  212. recordFilter |= MappedEvent::MidiKeyPressure;
  213. if (m_recordBox->findChild<QCheckBox*>("Channel Pressure")->isChecked())
  214. recordFilter |= MappedEvent::MidiChannelPressure;
  215. if (m_recordBox->findChild<QCheckBox*>("Pitch Bend")->isChecked())
  216. recordFilter |= MappedEvent::MidiPitchBend;
  217. if (m_recordBox->findChild<QCheckBox*>("Controller")->isChecked())
  218. recordFilter |= MappedEvent::MidiController;
  219. if (m_recordBox->findChild<QCheckBox*>("System Exclusive")->isChecked())
  220. recordFilter |= MappedEvent::MidiSystemMessage;
  221. m_doc->getStudio().setMIDIThruFilter(thruFilter);
  222. m_doc->getStudio().setMIDIRecordFilter(recordFilter);
  223. if (m_doc->getSequenceManager()) {
  224. m_doc->getSequenceManager()->filtersChanged(thruFilter, recordFilter);
  225. }
  226. setModified(false);
  227. }
  228. void
  229. MidiFilterDialog::accept()
  230. {
  231. slotApply();
  232. QDialog::accept();
  233. }
  234. void
  235. MidiFilterDialog::slotSetModified(int)
  236. {
  237. setModified(true);
  238. }
  239. void
  240. MidiFilterDialog::setModified(bool value)
  241. {
  242. if (m_modified == value)
  243. return ;
  244. if (! m_applyButton) return;
  245. if (value) {
  246. m_applyButton->setEnabled(true);
  247. } else {
  248. m_applyButton->setEnabled(false);
  249. }
  250. m_modified = value;
  251. }
  252. }
  253. #include "MidiFilterDialog.moc"