![]() |
Mixxx
|
00001 #include "playinterface.h" 00002 #include "scriptengine.h" 00003 #include <string.h> 00004 00005 #include "../controlobject.h" 00006 #include "../controlpotmeter.h" 00007 #include <qapplication.h> 00008 #include <qdatetime.h> 00009 00010 #include "interp.h" 00011 00012 PlayInterface::PlayInterface(ScriptControlQueue* q) { 00013 m_q = q; 00014 00015 m_process = -1; 00016 m_tag = -1; 00017 m_group = 0; 00018 m_name = 0; 00019 } 00020 00021 PlayInterface::~PlayInterface() { 00022 } 00023 00024 void PlayInterface::clearProcess() { 00025 m_process = -1; 00026 clearTag(); 00027 } 00028 00029 void PlayInterface::setProcess(int process) { 00030 if (m_process != -1) { 00031 qDebug("This process stuff won't work multithreaded yet..."); 00032 } 00033 m_process = process; 00034 } 00035 00036 void PlayInterface::setTag(int tag) { 00037 m_tag = tag; 00038 } 00039 00040 void PlayInterface::clearTag() { 00041 m_tag = -1; 00042 } 00043 00044 void PlayInterface::kill() { 00045 m_q->killProcess(m_process); 00046 } 00047 00048 void PlayInterface::killTag(int tag) { 00049 m_q->killTag(m_process, tag); 00050 } 00051 00052 void PlayInterface::test() { 00053 QDateTime base = QDateTime::currentDateTime(); 00054 m_q->interpolate("[Master]", "crossfader", &base, 2000, -1.0, 4000, \ 00055 1.0, m_process, m_tag); 00056 } 00057 00058 void PlayInterface::stop(int channel) { 00059 if (channel == 1) { 00060 ControlObject *p = ControlObject::getControl(ConfigKey("[Channel1]","play")); 00061 p->queueFromThread(0.); 00062 } else if (channel == 2) { 00063 ControlObject *p = ControlObject::getControl(ConfigKey("[Channel2]","play")); 00064 p->queueFromThread(0.); 00065 } else { 00066 qDebug("PlayInterface: No such channel %i to stop", channel); 00067 } 00068 } 00069 00070 void PlayInterface::play(int channel) { 00071 if (channel == 1) { 00072 ControlObject *p = ControlObject::getControl(ConfigKey("[Channel1]","play")); 00073 p->queueFromThread(1.); 00074 } else if (channel == 2) { 00075 ControlObject *p = ControlObject::getControl(ConfigKey("[Channel2]","play")); 00076 p->queueFromThread(1.); 00077 } else { 00078 qDebug("PlayInterface: No such channel %i to play", channel); 00079 } 00080 } 00081 00082 double PlayInterface::getFader() { 00083 ControlObject *pot = ControlObject::getControl(ConfigKey("[Master]", "crossfader")); 00084 return pot->get(); 00085 } 00086 00087 double PlayInterface::getValue(const char* group, const char* name) { 00088 ControlObject *pot = ControlObject::getControl(ConfigKey(group, name)); 00089 if (pot == NULL) { 00090 qDebug("Unknown control %s:%s", group, name); 00091 return 0.0; 00092 } 00093 return pot->get(); 00094 } 00095 00096 void PlayInterface::setFader(double fade) { 00097 qDebug("Set Fader %f", (float)fade); 00098 ControlObject *pot = ControlObject::getControl(ConfigKey("[Master]", "crossfader")); 00099 pot->queueFromThread(fade); 00100 } 00101 00102 void PlayInterface::startFadeCrossfader() { 00103 startFade("[Master]", "crossfader"); 00104 } 00105 00106 void PlayInterface::startList(const char* group, const char* name) { 00107 doStartFade(group, name, INTERP_NONE); 00108 } 00109 00110 void PlayInterface::startFade(const char* group, const char* name) { 00111 doStartFade(group, name, INTERP_LINEAR); 00112 } 00113 00114 void PlayInterface::doStartFade(const char* group, const char* name, \ 00115 int interp) { 00116 if (m_group != 0) { 00117 qDebug("startFade before endFade"); 00118 } 00119 m_group = group; 00120 m_name = name; 00121 m_times = new QLinkedList<int>(); 00122 m_values = new QLinkedList<double>(); 00123 m_time = QDateTime::currentDateTime(); 00124 00125 m_interp = interp; 00126 } 00127 00128 void PlayInterface::fadePoint(int time, double value) { 00129 m_times->append(time); 00130 m_values->append(value); 00131 } 00132 00133 void PlayInterface::point(int time, double value) { 00134 fadePoint(time, value); 00135 } 00136 00137 void PlayInterface::endList() { endFade(); } 00138 00139 void PlayInterface::endFade() { 00140 00141 QLinkedList<int>::const_iterator ti = m_times->constBegin(); 00142 QLinkedList<double>::const_iterator vi = m_values->constBegin(); 00143 00144 int last = *ti; 00145 double value = *vi; 00146 ti++; vi++; 00147 00148 if (m_interp == INTERP_NONE) { 00149 m_q->schedule(m_group, m_name, value, &m_time, last, \ 00150 m_process, m_tag); 00151 } 00152 00153 while(ti != m_times->end()) { 00154 if (m_interp == INTERP_LINEAR) { 00155 m_q->interpolate(m_group, m_name, &m_time, 00156 last, value, *ti, *vi, m_process, \ 00157 m_tag, TRUE); 00158 00159 } else { 00160 m_q->schedule(m_group, m_name, *vi, &m_time, *ti, \ 00161 m_process, m_tag); 00162 } 00163 00164 last = *ti; 00165 value = *vi; 00166 ti++; vi++; 00167 } 00168 00169 delete m_times; 00170 delete m_values; 00171 00172 m_group = 0; 00173 m_name = 0; 00174 } 00175 00176 void PlayInterface::playChannel1(int time, const char* path) { 00177 m_q->schedule(1, path, QDateTime::currentDateTime(), time, m_process, \ 00178 m_tag); 00179 } 00180 00181 void PlayInterface::playChannel2(int time, const char* path) { 00182 m_q->schedule(2, path, QDateTime::currentDateTime(), time, m_process, \ 00183 m_tag); 00184 }