1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A MIDI and audio sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7
8 Other copyrights also apply to some parts of this work. Please
9 see the AUTHORS file and individual file headers for details.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18
19 #include "TriggerSegmentDialog.h"
20 #include <QApplication>
21
22 #include "base/BaseProperties.h"
23 #include "misc/Strings.h"
24 #include "misc/ConfigGroups.h"
25 #include "base/Composition.h"
26 #include "base/TriggerSegment.h"
27 #include <QComboBox>
28 #include <QSettings>
29 #include <QDialog>
30 #include <QDialogButtonBox>
31 #include <QCheckBox>
32 #include <QFrame>
33 #include <QLabel>
34 #include <QString>
35 #include <QWidget>
36 #include <QVBoxLayout>
37 #include <QLayout>
38
39
40 namespace Rosegarden
41 {
42
TriggerSegmentDialog(QWidget * parent,Composition * composition)43 TriggerSegmentDialog::TriggerSegmentDialog(QWidget *parent,
44 Composition *composition) :
45 QDialog(parent),
46 m_composition(composition)
47 {
48 setModal(true);
49 setWindowTitle(tr("Trigger Segment"));
50 QGridLayout *metagrid = new QGridLayout;
51 setLayout(metagrid);
52
53 QFrame *frame = new QFrame(this);
54 metagrid->addWidget(frame, 0, 0);
55
56 frame->setContentsMargins(5, 5, 5, 5);
57 QGridLayout *layout = new QGridLayout;
58 layout->setSpacing(5);
59
60
61 QLabel *label = new QLabel(tr("Trigger segment: "));
62 layout->addWidget(label, 0, 0);
63
64 m_segment = new QComboBox(frame);
65 layout->addWidget(m_segment, 0, 1);
66
67 int n = 1;
68 for (Composition::triggersegmentcontaineriterator i =
69 m_composition->getTriggerSegments().begin();
70 i != m_composition->getTriggerSegments().end(); ++i) {
71 m_segment->addItem
72 (QString("%1. %2").arg(n++).arg(strtoqstr((*i)->getSegment()->getLabel())));
73 }
74
75 label = new QLabel(tr("Perform with timing: "));
76 layout->addWidget(label, 1, 0);
77
78 m_adjustTime = new QComboBox;
79 layout->addWidget(m_adjustTime, 1, 1);
80
81 m_adjustTime->addItem(tr("As stored"));
82 m_adjustTime->addItem(tr("Truncate if longer than note"));
83 m_adjustTime->addItem(tr("End at same time as note"));
84 m_adjustTime->addItem(tr("Stretch or squash segment to note duration"));
85
86 m_retune = new QCheckBox(tr("Adjust pitch to note"));
87 m_retune->setChecked(true);
88
89 layout->addWidget(m_retune, 2, 1);
90 frame->setLayout(layout);
91
92 setupFromConfig();
93
94 QDialogButtonBox *buttonBox
95 = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
96 metagrid->addWidget(buttonBox, 1, 0);
97 metagrid->setRowStretch(0, 10);
98 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
99 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
100 }
101
102 void
setupFromConfig()103 TriggerSegmentDialog::setupFromConfig()
104 {
105 QSettings settings;
106 settings.beginGroup( GeneralOptionsConfigGroup );
107
108 int seg = settings.value("triggersegmentlastornament", 0).toInt() ;
109 std::string timing = qstrtostr(settings.value("triggersegmenttiming",
110 strtoqstr(BaseProperties::TRIGGER_SEGMENT_ADJUST_SQUISH)).toString());
111 bool retune = qStrToBool( settings.value("triggersegmentretune", "true" ) ) ;
112
113 if (seg >= 0 && seg < m_segment->count())
114 m_segment->setCurrentIndex(seg);
115
116 if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_NONE) {
117 m_adjustTime->setCurrentIndex(0);
118 } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SQUISH) {
119 m_adjustTime->setCurrentIndex(3);
120 } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_START) {
121 m_adjustTime->setCurrentIndex(1);
122 } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_END) {
123 m_adjustTime->setCurrentIndex(2);
124 }
125
126 m_retune->setChecked(retune);
127
128 settings.endGroup();
129 }
130
131 TriggerSegmentId
getId() const132 TriggerSegmentDialog::getId() const
133 {
134 int ix = m_segment->currentIndex();
135
136 for (Composition::triggersegmentcontaineriterator i =
137 m_composition->getTriggerSegments().begin();
138 i != m_composition->getTriggerSegments().end(); ++i) {
139
140 if (ix == 0)
141 return (*i)->getId();
142 --ix;
143 }
144
145 return 0;
146 }
147
148 bool
getRetune() const149 TriggerSegmentDialog::getRetune() const
150 {
151 return m_retune->isChecked();
152 }
153
154 std::string
getTimeAdjust() const155 TriggerSegmentDialog::getTimeAdjust() const
156 {
157 int option = m_adjustTime->currentIndex();
158
159 switch (option) {
160
161 case 0:
162 return BaseProperties::TRIGGER_SEGMENT_ADJUST_NONE;
163 case 1:
164 return BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_START;
165 case 2:
166 return BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_END;
167 case 3:
168 return BaseProperties::TRIGGER_SEGMENT_ADJUST_SQUISH;
169
170 default:
171 return BaseProperties::TRIGGER_SEGMENT_ADJUST_NONE;
172 }
173 }
174
175 void
accept()176 TriggerSegmentDialog::accept()
177 {
178 QSettings settings;
179 settings.beginGroup( GeneralOptionsConfigGroup );
180
181 settings.setValue("triggersegmenttiming", strtoqstr(getTimeAdjust()));
182 settings.setValue("triggersegmentretune", m_retune->isChecked());
183 settings.setValue("triggersegmentlastornament", m_segment->currentIndex());
184
185 settings.endGroup();
186
187 QDialog::accept();
188 }
189
190 }
191