Player: works on Sailfish emulator.

For the moment, no sound on real Jolla device
This commit is contained in:
Louis-Joseph Fournier 2016-01-13 12:30:17 +01:00
parent 8926bbf8ea
commit 33eeeda8d6
2 changed files with 57 additions and 17 deletions

View file

@ -31,6 +31,8 @@ ApplicationWindow {
allowedOrientations: Orientation.All allowedOrientations: Orientation.All
property bool userRunning: true property bool userRunning: true
property bool userPlaying: false
property int dbFontSize: 100 property int dbFontSize: 100
property QtObject tuner property QtObject tuner
@ -40,10 +42,23 @@ ApplicationWindow {
object: Config object: Config
} }
Tuner {
id: tunerItem
temperament_idx: Config.temperament_idx
la: Config.la
running: Qt.application.active && app.userRunning
playing: Qt.application.active && app.userPlaying
Component.onCompleted: app.tuner = tunerItem
}
initialPage: Component { initialPage: Component {
Page { Page {
id: page id: page
allowedOrientations: Orientation.All allowedOrientations: Orientation.All
property bool running: true
property bool tunerRunning: running && status == PageStatus.Active
SilicaFlickable { SilicaFlickable {
anchors.fill: parent anchors.fill: parent
@ -63,25 +78,51 @@ ApplicationWindow {
anchors.fill: parent anchors.fill: parent
theme: Theme theme: Theme
tuner: app.tuner tuner: app.tuner
onToggleRun: page.running ^= true
} }
} }
onTunerRunningChanged: app.userRunning = tunerRunning
Tuner {
id: tunerObject
running: Qt.application.active && page.status == PageStatus.Active && app.userRunning
temperament_idx: Config.temperament_idx
la: Config.la
}
Component.onCompleted: {
app.tuner = tunerObject
screen.toggleRun.connect(app.toggleRun)
}
} }
} }
Component {
id: player
Page {
id: page
allowedOrientations: Orientation.All
property bool playing: false
property bool tunerPlaying: playing && status == PageStatus.Active
SilicaFlickable {
anchors.fill: parent
PullDownMenu {
MenuItem {
text: qsTr("Configuration")
onClicked: {
var confpage = pageStack.push(Qt.resolvedUrl("ConfigurePageSailfish.qml"), { tuner: app.tuner })
confpage.configChanged.connect(saver.save)
}
}
}
PlayerScreen {
id: screen
anchors.fill: parent
theme: Theme
tuner: app.tuner
onTogglePlay: page.playing ^= true
}
}
onTunerPlayingChanged: app.userPlaying = tunerPlaying
}
}
cover: Component { cover: Component {
CoverBackground { CoverBackground {
SimpleDisplay { SimpleDisplay {
@ -91,7 +132,5 @@ ApplicationWindow {
} }
} }
function toggleRun() { Component.onCompleted: pageStack.pushAttached(player)
app.userRunning = app.userRunning ? false : true
}
} }

View file

@ -281,11 +281,12 @@ void TunerWorker::Entry()
if (pa_simple_write(p_play, buffer, nbSampleBuffer << 1, nullptr) < 0) { if (pa_simple_write(p_play, buffer, nbSampleBuffer << 1, nullptr) < 0) {
cerr << "audio write failed" << endl; cerr << "audio write failed" << endl;
} }
else cout << "audio written" << endl;
} // playing } // playing
// prevent screen blanking // prevent screen blanking
nb_sample_running += nbSampleBuffer; nb_sample_running += nbSampleBuffer;
if (nb_sample_running >= nbSamplePreventBlanking && running) { if (nb_sample_running >= nbSamplePreventBlanking && (running || playing)) {
nb_sample_running = 0; nb_sample_running = 0;
blank_prevent(true); blank_prevent(true);
} }