Skip to content

Commit

Permalink
sequence info dialog enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolcl committed Aug 24, 2024
1 parent 4bcb6f7 commit b6e37a1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
43 changes: 35 additions & 8 deletions guiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QActionGroup>
#include <QDesktopServices>
#include <QFileDialog>
#include <QToolTip>
#include <QMessageBox>
#include <QInputDialog>
#include <QFileInfo>
#include <QInputDialog>
#include <QMessageBox>
#include <QMimeData>
#include <QStandardPaths>
#include <QTime>
#include <QTimer>
#include <QMimeData>
#include <QToolTip>
#include <QtMath>
#include <QActionGroup>
#include <QStandardPaths>
#include <QDesktopServices>
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
#include <QDesktopWidget>
#else
Expand Down Expand Up @@ -1034,11 +1034,18 @@ void GUIPlayer::slotSwitchLanguage(QAction *action)
void GUIPlayer::slotFileInfo()
{
QString infostr;
QLocale locale(Settings::instance()->language());
if (m_player->song()->currentFile().isEmpty())
infostr = tr("<b>No file loaded</b>");
else {
infostr = tr("File: <b>%1</b><br>").arg(m_player->song()->currentFile());
QString s = m_player->song()->getFileFormat();

QFileInfo finfo(m_player->song()->currentFullFileName());
QString s = locale.toString(finfo.lastModified(), QLocale::LongFormat);
if (!s.isEmpty())
infostr += tr("Date: <b>%1</b><br/>").arg(s);

s = m_player->song()->getFileFormat();
if (!s.isEmpty())
infostr += tr("Format: <b>%1</b><br>").arg(s);

Expand Down Expand Up @@ -1070,6 +1077,26 @@ void GUIPlayer::slotFileInfo()
if (!s.isEmpty())
infostr += tr("Karaoke things: <b>%1</b><br>").arg(s);

s = QString::number(m_player->song()->getNumTracks());
if (!s.isEmpty())
infostr += tr("Number of tracks: <b>%1</b><br/>").arg(s);

s = QString::number(m_player->song()->size());
if (!s.isEmpty())
infostr += tr("Number of events: <b>%1</b><br/>").arg(s);

s = QString::number(m_player->song()->getDivision());
if (!s.isEmpty())
infostr += tr("Division: <b>%1 ppqn</b><br/>").arg(s);

s = QString::number(m_player->initialBPM());
if (!s.isEmpty())
infostr += tr("Initial tempo: <b>%7 bpm</b><br/>").arg(s);

s = m_player->song()->duration();
if (!s.isEmpty())
infostr += tr("Duration: <b>%1</b><br/>").arg(s);

s = m_player->song()->getMetadataInfo();
if (!s.isEmpty())
infostr += s;
Expand Down
9 changes: 7 additions & 2 deletions seqplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ void SequencePlayer::playerLoop()

emit songStopped();
if (!m_song.hasMoreEvents()) {
qDebug() << "Final Song Position:" << m_songPositionTicks
<< (currentTime - startTime).count() / 1e9;
// qDebug() << "Final Song Position:" << m_songPositionTicks
// << (currentTime - startTime).count() / 1e9;
emit songFinished();
}
dispatcher->processEvents(eventFilter);
Expand All @@ -366,6 +366,11 @@ qreal SequencePlayer::currentBPM() const
return bpm(m_song.currentTempo());
}

qreal SequencePlayer::initialBPM() const
{
return bpm(m_song.initialTempo());
}

Sequence *SequencePlayer::song()
{
return &m_song;
Expand Down
1 change: 1 addition & 0 deletions seqplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SequencePlayer : public QObject
drumstick::rt::MIDIOutput* port() const;
qreal bpm(qreal tempo) const;
qreal currentBPM() const;
qreal initialBPM() const;
bool isRunning();
Sequence *song();
int getPosition();
Expand Down
17 changes: 17 additions & 0 deletions sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ void Sequence::clear()
m_lowestMidiNote = 127;
m_highestMidiNote = 0;
m_curTrack = 0;
m_duration = 0;
m_initialTempo = 0;
m_firstTime = true;
m_codec = nullptr;
m_infoMap.clear();
for(int i=0; i<MIDI_STD_CHANNELS; ++i) {
Expand Down Expand Up @@ -422,6 +425,16 @@ int Sequence::errorsCount() const
return m_loadingErrors.size();
}

QString Sequence::duration() const
{
std::chrono::microseconds us = timeOfTicks(m_ticksDuration);
qreal seconds = us.count() / 1e6;
double fractpart, intpart;
fractpart = modf(seconds, &intpart);
QTime t = QTime(0, 0).addSecs(intpart).addMSecs(ceil(fractpart * 1000));
return t.toString("hh:mm:ss.zzz");
}

QTextCodec *Sequence::codec() const
{
return m_codec;
Expand Down Expand Up @@ -613,6 +626,10 @@ void Sequence::updateTempo(qreal newTempo)
//qDebug() << Q_FUNC_INFO << newTempo;
m_tempo = newTempo;
timeCalculations();
if (m_firstTime) {
m_initialTempo = newTempo;
m_firstTime = false;
};
}
}

Expand Down
6 changes: 6 additions & 0 deletions sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class Sequence : public QObject
QString loadingErrors() const;
int errorsCount() const;

qsizetype size() const { return m_list.size(); }
qreal initialTempo() const { return m_initialTempo; }
QString duration() const;

signals:
void loadingStart(int size);
void loadingProgress(int pos);
Expand Down Expand Up @@ -289,6 +293,8 @@ public slots:
QMap<int, int> m_trkChannel;
QMap<QString, QString> m_infoMap;
QList<QString> m_loadingErrors;
bool m_firstTime{true};
qreal m_initialTempo{0};
};

#endif // SEQUENCE_H

0 comments on commit b6e37a1

Please sign in to comment.