summaryrefslogtreecommitdiffstats
path: root/src/gui/configuration/LatencyConfigurationPage.cpp
blob: 4ac9390a80e9b711fe21bbdfbe82db4ef1719e54 (plain)
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
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */

/*
    Rosegarden
    A MIDI and audio sequencer and musical notation editor.
 
    This program is Copyright 2000-2008
        Guillaume Laurent   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <richard.bown@ferventsoftware.com>
 
    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
    Bown to claim authorship of this work have been asserted.
 
    Other copyrights also apply to some parts of this work.  Please
    see the AUTHORS file and individual file headers for details.
 
    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 "LatencyConfigurationPage.h"
#include <tqlayout.h>

#include "document/ConfigGroups.h"
#include "ConfigurationPage.h"
#include "document/RosegardenGUIDoc.h"
#include "TabbedConfigurationPage.h"
#include <kconfig.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqslider.h>
#include <tqstring.h>
#include <tqtabwidget.h>
#include <tqwidget.h>


namespace Rosegarden
{

LatencyConfigurationPage::LatencyConfigurationPage(RosegardenGUIDoc *doc,
        KConfig *cfg,
        TQWidget *parent,
        const char *name)
        : TabbedConfigurationPage(doc, cfg, parent, name)
{
    //     Configuration &config = doc->getConfiguration();
    m_cfg->setGroup(LatencyOptionsConfigGroup);

#ifdef NOT_DEFINED
#ifdef HAVE_LIBJACK

    frame = new TQFrame(m_tabWidget, i18n("JACK latency"));
    layout = new TQGridLayout(frame, 6, 5, 10, 10);

    layout->addMultiCellWidget(new TQLabel(i18n("Use the \"Fetch JACK latencies\" button to discover the latency values set at\nthe sequencer.  It's recommended that you use the returned values but it's also\npossible to override them manually using the sliders.  Note that if you change\nyour JACK server parameters you should always fetch the latency values again.\nThe latency values will be stored by Rosegarden for use next time."), frame),
                               0, 0,
                               0, 3);

    layout->addWidget(new TQLabel(i18n("JACK playback latency (in ms)"), frame), 1, 0);
    layout->addWidget(new TQLabel(i18n("JACK record latency (in ms)"), frame), 3, 0);

    m_fetchLatencyValues = new TQPushButton(i18n("Fetch JACK latencies"),
                                           frame);

    layout->addWidget(m_fetchLatencyValues, 1, 3);

    connect(m_fetchLatencyValues, TQT_SIGNAL(released()),
            TQT_SLOT(slotFetchLatencyValues()));

    int jackPlaybackValue = (m_cfg->readLongNumEntry(
                                 "jackplaybacklatencyusec", 0) / 1000) +
                            (m_cfg->readLongNumEntry(
                                 "jackplaybacklatencysec", 0) * 1000);

    m_jackPlayback = new TQSlider(Horizontal, frame);
    m_jackPlayback->setTickmarks(TQSlider::Below);
    layout->addMultiCellWidget(m_jackPlayback, 3, 3, 2, 3);

    TQLabel *jackPlaybackLabel = new TQLabel(TQString("%1").arg(jackPlaybackValue),
                                           frame);
    layout->addWidget(jackPlaybackLabel, 2, 2, Qt::AlignHCenter);
    connect(m_jackPlayback, TQT_SIGNAL(valueChanged(int)),
            jackPlaybackLabel, TQT_SLOT(setNum(int)));

    m_jackPlayback->setMinValue(0);
    layout->addWidget(new TQLabel("0", frame), 3, 1, Qt::AlignRight);

    m_jackPlayback->setMaxValue(500);
    layout->addWidget(new TQLabel("500", frame), 3, 4, Qt::AlignLeft);

    m_jackPlayback->setValue(jackPlaybackValue);

    int jackRecordValue = (m_cfg->readLongNumEntry(
                               "jackrecordlatencyusec", 0) / 1000) +
                          (m_cfg->readLongNumEntry(
                               "jackrecordlatencysec", 0) * 1000);

    m_jackRecord = new TQSlider(Horizontal, frame);
    m_jackRecord->setTickmarks(TQSlider::Below);
    layout->addMultiCellWidget(m_jackRecord, 5, 5, 2, 3);

    TQLabel *jackRecordLabel = new TQLabel(TQString("%1").arg(jackRecordValue),
                                         frame);
    layout->addWidget(jackRecordLabel, 4, 2, Qt::AlignHCenter);
    connect(m_jackRecord, TQT_SIGNAL(valueChanged(int)),
            jackRecordLabel, TQT_SLOT(setNum(int)));

    m_jackRecord->setMinValue(0);
    layout->addWidget(new TQLabel("0", frame), 5, 1, Qt::AlignRight);

    m_jackRecord->setMaxValue(500);
    m_jackRecord->setValue(jackRecordValue);
    layout->addWidget(new TQLabel("500", frame), 5, 4, Qt::AlignLeft);

    addTab(frame, i18n("JACK Latency"));
#endif  // HAVE_LIBJACK
#endif // NOT_DEFINED

}

void LatencyConfigurationPage::apply()
{
    m_cfg->setGroup(LatencyOptionsConfigGroup);

#ifdef HAVE_LIBJACK

    int jackPlayback = getJACKPlaybackValue();
    m_cfg->writeEntry("jackplaybacklatencysec", jackPlayback / 1000);
    m_cfg->writeEntry("jackplaybacklatencyusec", jackPlayback * 1000);

    int jackRecord = getJACKRecordValue();
    m_cfg->writeEntry("jackrecordlatencysec", jackRecord / 1000);
    m_cfg->writeEntry("jackrecordlatencyusec", jackRecord * 1000);

#endif  // HAVE_LIBJACK
}

void LatencyConfigurationPage::slotFetchLatencyValues()
{
    int jackPlaybackValue = m_doc->getAudioPlayLatency().msec() +
                            m_doc->getAudioPlayLatency().sec * 1000;

    m_jackPlayback->setValue(jackPlaybackValue);

    int jackRecordValue = m_doc->getAudioRecordLatency().msec() +
                          m_doc->getAudioRecordLatency().sec * 1000;
    m_jackRecord->setValue(jackRecordValue);
}

}
#include "LatencyConfigurationPage.moc"