Skip to content

Commit

Permalink
album dialog function comment, relative filepath improvement, playbac…
Browse files Browse the repository at this point in the history
…k for album mode
  • Loading branch information
SKefalidis committed Jun 5, 2020
1 parent 80315c4 commit b75a206
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 32 deletions.
30 changes: 5 additions & 25 deletions libmscore/album.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@ void AlbumItem::readAlbumItem(XmlReader &reader)
_fileInfo.setFile(reader.readElementText());
} else if (tag == "relativePath") {
if (!_fileInfo.exists()) {
auto itemPathList = reader.readElementText().split("/");
auto albumPathList = album->_fileInfo.absolutePath().split("/");
int j = itemPathList.removeAll("..");
for (int i = 0; i < j; i++) {
albumPathList.removeLast();
}
QString relativePath(albumPathList.join("/") + "/" + itemPathList.join("/"));
std::cout << "relative path: " << relativePath.toStdString() << std::endl;
_fileInfo.setFile(relativePath);
QDir dir(album->_fileInfo.dir());
QString relativePath = reader.readElementText();
_fileInfo.setFile(dir, relativePath);
} else {
reader.readElementText();
}
Expand All @@ -114,22 +108,8 @@ void AlbumItem::writeAlbumItem(XmlWriter &writer)
writer.stag("Score");
writer.tag("alias", "");
writer.tag("path", _fileInfo.absoluteFilePath());
auto itemPathList = _fileInfo.absoluteFilePath().split("/");
auto albumPathList = album->_fileInfo.absoluteFilePath().split("/");
QString relativePath;
for (int i = 0; i < albumPathList.size(); i++) {
if (itemPathList.at(i) != albumPathList.at(i)) {
for (int j = 0; j < i; j++) {
itemPathList.removeFirst();
}
relativePath = itemPathList.join("/"); // TODO: \ for windows
for (int j = 1; j < albumPathList.size() - i; j++) {
relativePath.prepend("../");
}
relativePath.prepend("./");
break;
}
}
QDir dir(album->_fileInfo.dir());
QString relativePath = dir.relativeFilePath(_fileInfo.absoluteFilePath());
writer.tag("relativePath", relativePath);
writer.tag("enabled", enabled);
writer.etag();
Expand Down
23 changes: 16 additions & 7 deletions mscore/albummanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ void AlbumManager::changeMode(bool throwaway)
{
if (scoreModeButton->isChecked()) {
albumModeButton->setChecked(false);
mscore->closeScore(tempScore); // also frees
tempScore = nullptr;
} else if (albumModeButton->isChecked()) {
scoreModeButton->setChecked(false);
if (!tempScore) {
tempScore = _items.at(0)->albumItem->score->clone();
tempScore = _items.at(0)->albumItem->score->clone(); // TODO: clone breaks editing sync for the 1st movement
mscore->setCurrentScoreView(mscore->appendScore(tempScore));
mscore->getTab1()->setTabText(mscore->getTab1()->count() - 1, "Temporary Album Score");
for (auto item : _items) {
Expand All @@ -154,7 +156,8 @@ void AlbumManager::changeMode(bool throwaway)
tempScore->setLayoutAll();
tempScore->update();

// addScore(tempScore);
// _album->addScore(tempScore);
// addAlbumItem(_album->_albumItems.back());
}
} else {
Q_ASSERT(false);
Expand All @@ -172,12 +175,15 @@ void AlbumManager::playAlbum()

if (i < _items.size()) {
if (_items.at(i)->albumItem->enabled) {
if (_items.at(i)->albumItem->score) {
mscore->openScore(_items.at(i)->albumItem->_fileInfo.absoluteFilePath()); // what if the files have not been saved?
} else {
_items.at(i)->albumItem->score = mscore->openScore(_items.at(i)->albumItem->_fileInfo.absoluteFilePath());
if (scoreModeButton->isChecked()) {
if (_items.at(i)->albumItem->score) {
mscore->openScore(_items.at(i)->albumItem->_fileInfo.absoluteFilePath()); // what if the files have not been saved?
} else {
_items.at(i)->albumItem->score = mscore->openScore(_items.at(i)->albumItem->_fileInfo.absoluteFilePath());
}
mscore->currentScoreView()->gotoMeasure(_items.at(i)->albumItem->score->firstMeasure()); // rewind before playing
}
mscore->currentScoreView()->gotoMeasure(_items.at(i)->albumItem->score->firstMeasure()); // rewind before playing

if (i == 0) {
seq->start();
} else {
Expand All @@ -187,6 +193,9 @@ void AlbumManager::playAlbum()
connect(seq, &Seq::stopped, this, static_cast<void (AlbumManager::*)()>(&AlbumManager::playAlbum));
}
} else {
if (albumModeButton->isChecked()) {
seq->setNextScore();
}
playAlbum();
}
} else {
Expand Down
21 changes: 21 additions & 0 deletions mscore/albummanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include "ui_albummanagerdialog.h"

namespace Ms {

//---------------------------------------------------------
// AlbumManagerDialog
//---------------------------------------------------------

AlbumManagerDialog::AlbumManagerDialog(QWidget* parent) :
QDialog(parent)
{
Expand All @@ -36,24 +41,40 @@ AlbumManagerDialog::~AlbumManagerDialog()
delete ui;
}

//---------------------------------------------------------
// start
//---------------------------------------------------------

void AlbumManagerDialog::start()
{
update();
show();
}

//---------------------------------------------------------
// apply
//---------------------------------------------------------

void AlbumManagerDialog::apply()
{
AlbumManager* albumManager = static_cast<AlbumManager*>(parent());
albumManager->album()->playbackDelay = playbackDelayBox->value();
}

//---------------------------------------------------------
// update
//---------------------------------------------------------

void AlbumManagerDialog::update()
{
AlbumManager* albumManager = static_cast<AlbumManager*>(parent());
playbackDelayBox->setValue(albumManager->album()->playbackDelay);
}

//---------------------------------------------------------
// buttonBoxClicked
//---------------------------------------------------------

void AlbumManagerDialog::buttonBoxClicked(QAbstractButton* button)
{
switch (buttonBox->standardButton(button)) {
Expand Down
2 changes: 2 additions & 0 deletions mscore/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ static const char* stateName(ViewState s)

void ScoreView::seqStopped()
{
std::cout << "seqStopped" << std::endl;
changeState(ViewState::NORMAL);
}

Expand Down Expand Up @@ -1187,6 +1188,7 @@ void ScoreView::changeState(ViewState s)
endFotoDrag();
break;
case ViewState::PLAY:
std::cout << "stop play" << std::endl;
seq->stop();
break;
case ViewState::EDIT:
Expand Down
40 changes: 40 additions & 0 deletions mscore/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ Seq::Seq()
running = false;
playlistChanged = false;
cs = 0;
dominantScore = nullptr;
nextMovementIndex = -1;
cv = 0;
tackRemain = 0;
tickRemain = 0;
Expand Down Expand Up @@ -208,6 +210,7 @@ Seq::~Seq()

void Seq::setScoreView(ScoreView* v)
{
std::cout << "setScoreView" << std::endl;
if (oggInit) {
ov_clear(&vf);
oggInit = false;
Expand All @@ -221,6 +224,39 @@ void Seq::setScoreView(ScoreView* v)
disconnect(cs, SIGNAL(playlistChanged()), this, SLOT(setPlaylistChanged()));
}
cs = cv ? cv->score()->masterScore() : 0;
dominantScore = cs;
nextMovementIndex = dominantScore ? 1 : 0;
midi = MidiRenderer(cs);
midi.setMinChunkSize(10);

if (!heartBeatTimer->isActive()) {
heartBeatTimer->start(20); // msec
}
playlistChanged = true;
_synti->reset();
if (cs) {
initInstruments();
connect(cs, SIGNAL(playlistChanged()), this, SLOT(setPlaylistChanged()));
}
}

//---------------------------------------------------------
// setNextScore
/// used to setup next movement for playback
/// FIXME: probably crahses if the score is closed
//---------------------------------------------------------

void Seq::setNextScore()
{
std::cout << "next score" << std::endl;
if (nextMovementIndex < dominantScore->movements()->size()) {
cs = dominantScore->movements()->at(nextMovementIndex);
nextMovementIndex++;
} else {
cs = dominantScore;
nextMovementIndex = 1;
}

midi = MidiRenderer(cs);
midi.setMinChunkSize(10);

Expand Down Expand Up @@ -383,6 +419,7 @@ void Seq::start()

void Seq::stop()
{
std::cout << "stop" << std::endl;
const bool seqStopped = (state == Transport::STOP);
const bool driverStopped = !_driver || _driver->getState() == Transport::STOP;
if (seqStopped && driverStopped) {
Expand Down Expand Up @@ -419,6 +456,7 @@ void Seq::stop()

void Seq::stopWait()
{
std::cout << "stop wait" << std::endl;
stop();
QWaitCondition sleep;
int idx = 0;
Expand Down Expand Up @@ -783,6 +821,8 @@ void Seq::process(unsigned framesPerPeriod, float* buffer)
}
// Got a message from JACK Transport panel: Stop
else if (state == Transport::PLAY && driverState == Transport::STOP) {
std::cout << "HERE IT IS" << std::endl;
setNextScore();
state = Transport::STOP;
// Muting all notes
stopNotes(-1, true);
Expand Down
3 changes: 3 additions & 0 deletions mscore/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class Seq : public QObject, public Sequencer

mutable QMutex mutex;

MasterScore* dominantScore;
int nextMovementIndex;
MasterScore* cs;
ScoreView* cv;
bool running; // true if sequencer is available
Expand Down Expand Up @@ -269,6 +271,7 @@ public slots:
void setController(int, int, int);
virtual void sendEvent(const NPlayEvent&);
void setScoreView(ScoreView*);
void setNextScore();
MasterScore* score() const { return cs; }
ScoreView* viewer() const { return cv; }
void initInstruments(bool realTime = false);
Expand Down

0 comments on commit b75a206

Please sign in to comment.