Merge lp:~mixxxdevelopers/mixxx/fixes_midi_burnout into lp:~mixxxdevelopers/mixxx/trunk

Proposed by William Good
Status: Merged
Merged at revision: 3257
Proposed branch: lp:~mixxxdevelopers/mixxx/fixes_midi_burnout
Merge into: lp:~mixxxdevelopers/mixxx/trunk
Diff against target: 147 lines (+49/-7)
7 files modified
mixxx/build/depends.py (+1/-0)
mixxx/src/controllers/controller.h (+3/-2)
mixxx/src/controllers/controllermanager.cpp (+6/-1)
mixxx/src/controllers/midi/portmidicontroller.cpp (+4/-3)
mixxx/src/controllers/midi/portmidicontroller.h (+1/-1)
mixxx/src/sleepableqthread.cpp (+8/-0)
mixxx/src/sleepableqthread.h (+26/-0)
To merge this branch: bzr merge lp:~mixxxdevelopers/mixxx/fixes_midi_burnout
Reviewer Review Type Date Requested Status
Mixxx Development Team Pending
Review via email: mp+106679@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mixxx/build/depends.py'
2--- mixxx/build/depends.py 2012-05-19 00:27:41 +0000
3+++ mixxx/build/depends.py 2012-05-21 17:49:20 +0000
4@@ -581,6 +581,7 @@
5 "tapfilter.cpp",
6
7 "util/pa_ringbuffer.c",
8+ "sleepableqthread.cpp",
9
10 # Add the QRC file which compiles in some extra resources
11 # (prefs icons, etc.)
12
13=== modified file 'mixxx/src/controllers/controller.h'
14--- mixxx/src/controllers/controller.h 2012-04-29 01:40:37 +0000
15+++ mixxx/src/controllers/controller.h 2012-05-21 17:49:20 +0000
16@@ -122,8 +122,9 @@
17 private slots:
18 virtual int open() = 0;
19 virtual int close() = 0;
20- // Requests that the device poll if it is a polling device.
21- virtual void poll() { }
22+ // Requests that the device poll if it is a polling device. Returns true
23+ // if events were handled.
24+ virtual bool poll() { return false; }
25
26 private:
27 // This must be reimplemented by sub-classes desiring to send raw bytes to a
28
29=== modified file 'mixxx/src/controllers/controllermanager.cpp'
30--- mixxx/src/controllers/controllermanager.cpp 2012-05-01 14:45:33 +0000
31+++ mixxx/src/controllers/controllermanager.cpp 2012-05-21 17:49:20 +0000
32@@ -7,6 +7,7 @@
33
34 #include <QSet>
35
36+#include "sleepableqthread.h"
37 #include "controllers/controllermanager.h"
38 #include "controllers/defs_controllers.h"
39 #include "controllers/controllerlearningeventfilter.h"
40@@ -246,11 +247,15 @@
41 }
42
43 void ControllerManager::pollDevices() {
44+ bool eventsProcessed(false);
45 foreach (Controller* pDevice, m_controllers) {
46 if (pDevice->isOpen() && pDevice->isPolling()) {
47- pDevice->poll();
48+ eventsProcessed = pDevice->poll() || eventsProcessed;
49 }
50 }
51+ // if we didn't process anything, sleep a bit to avoid burning/hogging
52+ // cpu cycles
53+ if (!eventsProcessed) SleepableQThread::msleep(1);
54 }
55
56 QList<QString> ControllerManager::getPresetList(QString extension) {
57
58=== modified file 'mixxx/src/controllers/midi/portmidicontroller.cpp'
59--- mixxx/src/controllers/midi/portmidicontroller.cpp 2012-04-24 05:42:04 +0000
60+++ mixxx/src/controllers/midi/portmidicontroller.cpp 2012-05-21 17:49:20 +0000
61@@ -134,18 +134,18 @@
62 return 0;
63 }
64
65-void PortMidiController::poll() {
66+bool PortMidiController::poll() {
67 // Poll the controller for new data
68 int numEvents = 0;
69
70 if (m_pInputStream) {
71 PmError gotEvents = Pm_Poll(m_pInputStream);
72 if (gotEvents == FALSE) {
73- return;
74+ return false;
75 }
76 if (gotEvents < 0) {
77 qWarning() << "PortMidi error:" << Pm_GetErrorText(gotEvents);
78- return;
79+ return false;
80 }
81
82 numEvents = Pm_Read(m_pInputStream, m_midiBuffer, MIXXX_PORTMIDI_BUFFER_LEN);
83@@ -198,6 +198,7 @@
84 m_cReceiveMsg_index = 0;
85 }
86 }
87+ return numEvents > 0;
88 }
89
90 void PortMidiController::send(unsigned int word) {
91
92=== modified file 'mixxx/src/controllers/midi/portmidicontroller.h'
93--- mixxx/src/controllers/midi/portmidicontroller.h 2012-04-24 07:19:23 +0000
94+++ mixxx/src/controllers/midi/portmidicontroller.h 2012-05-21 17:49:20 +0000
95@@ -36,7 +36,7 @@
96 private slots:
97 virtual int open();
98 virtual int close();
99- virtual void poll();
100+ virtual bool poll();
101
102 private:
103 void send(unsigned int word);
104
105=== added file 'mixxx/src/sleepableqthread.cpp'
106--- mixxx/src/sleepableqthread.cpp 1970-01-01 00:00:00 +0000
107+++ mixxx/src/sleepableqthread.cpp 2012-05-21 17:49:20 +0000
108@@ -0,0 +1,8 @@
109+// sleepableqthread.cpp
110+// Created May 21, 2012 by Bill Good <bkgood at gmail dot com>
111+//
112+// This is just a dummy file meant to be shoved in the build list so that moc
113+// runs on the class and linker errors are avoided.
114+
115+#include "sleepableqthread.h"
116+
117
118=== added file 'mixxx/src/sleepableqthread.h'
119--- mixxx/src/sleepableqthread.h 1970-01-01 00:00:00 +0000
120+++ mixxx/src/sleepableqthread.h 2012-05-21 17:49:20 +0000
121@@ -0,0 +1,26 @@
122+// sleepableqthread.h
123+// Created May 21, 2012 by Bill Good <bkgood at gmail dot com>
124+
125+#include <QThread>
126+
127+// Subclass of QThread exposing static sleep methods. Qt developers know
128+// better than us and therefore made these methods protected but I'm a
129+// rebel.
130+class SleepableQThread : public QThread {
131+ Q_OBJECT;
132+ Q_DISABLE_COPY(SleepableQThread);
133+public:
134+ explicit SleepableQThread(QObject *parent = NULL) : QThread(parent) { }
135+ virtual ~SleepableQThread() { }
136+ static void sleep(unsigned long secs) {
137+ QThread::sleep(secs);
138+ }
139+
140+ static void msleep(unsigned long msecs) {
141+ QThread::msleep(msecs);
142+ }
143+
144+ static void usleep(unsigned long usecs) {
145+ QThread::usleep(usecs);
146+ }
147+};

Subscribers

People subscribed via source and target branches