Create a AudioView widget for audio-only streams

Currently Codeine will show a blank area when playing an audio-only
file, such as music.  This patch adds a new widget that contains an
instance of the Analyzer::Block class, so instead of a blank area it
contains a "visualizer" of sorts.

Signed-off-by: mio <stigma@disroot.org>
(cherry picked from commit 5cfecec409)
r14.1.x
mio 8 months ago
parent 3f8d1f80ca
commit b8894a29b2

@ -35,6 +35,7 @@ tde_add_executable( ${PROJECT_NAME} AUTOMOC
playDialog.cpp playDialog.cpp
listView.cpp listView.cpp
adjustSizeButton.cpp adjustSizeButton.cpp
audioView.cpp
fullScreenAction.cpp fullScreenAction.cpp
insertAspectRatioMenuItems.cpp insertAspectRatioMenuItems.cpp
playlistFile.cpp playlistFile.cpp

@ -585,7 +585,12 @@ void Analyzer::Block::determineStep()
// I calculated the value 30 based on some trial and error // I calculated the value 30 based on some trial and error
const double fallTime = 30 * m_rows; const double fallTime = 30 * m_rows;
m_step = double(m_rows * 80) / fallTime; // 80 = ~milliseconds between signals with audio data
// The number of milliseconds between signals with audio data is about 80,
// however, basing the step off of that value causes some undersireable
// effects in the analyzer (high-end blocks constantly appearing/disappearing).
// 44 seems to be a good mid-point.
m_step = double(m_rows * 44) / fallTime;
} }
void Analyzer::Block::drawBackground() void Analyzer::Block::drawBackground()

@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2025 mio <stigma@disroot.org>
//
// SPDX-License-Identifier: GPL-2.0-or-later.
#include "audioView.h"
#include <tqlayout.h>
#include "analyzer.h"
namespace Codeine
{
AudioView::AudioView(TQWidget *parent, const char *name)
: TQFrame(parent, name)
{
auto *layout = new TQHBoxLayout(this);
m_analyzer = new Analyzer::Block(this);
// We subtract one from the below to remove excess padding.
// 36 blocks for the max/min height is arbitrary, but looks okay.
m_analyzer->setMaximumSize((Analyzer::Block::MAX_COLUMNS / 2) * (Analyzer::Block::WIDTH + 1) - 1,
36 * (Analyzer::Block::HEIGHT + 1) - 1);
m_analyzer->setMinimumSize(Analyzer::Block::WIDTH * Analyzer::Block::MIN_COLUMNS,
36 * (Analyzer::Block::HEIGHT + 1) - 1);
layout->addWidget(m_analyzer);
}
}

@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2025 mio <stigma@disroot.org>
//
// SPDX-License-Identifier: GPL-2.0-or-later.
#ifndef CODEINE_AUDIOVIEW_H
#define CODEINE_AUDIOVIEW_H
#include <tqframe.h>
namespace Codeine
{
class AudioView : public TQFrame
{
public:
AudioView(TQWidget *parent, const char *name = nullptr);
private:
TQWidget *m_analyzer;
};
}
#endif /* CODEINE_AUDIOVIEW_H */

@ -22,11 +22,13 @@
#include <tqlayout.h> //ctor #include <tqlayout.h> //ctor
#include <tqpopupmenu.h> //because XMLGUI is poorly designed #include <tqpopupmenu.h> //because XMLGUI is poorly designed
#include <tqobjectlist.h> #include <tqobjectlist.h>
#include <tqwidgetstack.h>
#include "../debug.h" #include "../debug.h"
#include "../mxcl.library.h" #include "../mxcl.library.h"
#include "actions.h" #include "actions.h"
#include "analyzer.h" #include "analyzer.h"
#include "audioView.h"
#include "codeineConfig.h" #include "codeineConfig.h"
#include "extern.h" //dialog creation function definitions #include "extern.h" //dialog creation function definitions
#include "fullScreenAction.h" #include "fullScreenAction.h"
@ -70,8 +72,19 @@ MainWindow::MainWindow()
kapp->setMainWidget( this ); kapp->setMainWidget( this );
m_widgetStack = new TQWidgetStack(this, "m_widgetStack");
new VideoWindow( this ); new VideoWindow( this );
setCentralWidget( videoWindow() );
m_audioView = new AudioView(this, "m_audioView");
// videoWindow() will be the initial widget.
// m_audioView is raised when no video track is present.
m_widgetStack->addWidget(videoWindow());
m_widgetStack->addWidget(m_audioView);
setCentralWidget(m_widgetStack);
setFocusProxy( videoWindow() ); // essential! See VideoWindow::event(), TQEvent::FocusOut setFocusProxy( videoWindow() ); // essential! See VideoWindow::event(), TQEvent::FocusOut
// these have no affect beccause "KDE Knows Best" FFS // these have no affect beccause "KDE Knows Best" FFS
@ -523,7 +536,6 @@ show_toolbar:
//we aren't managed by mainWindow when at FullScreen //we aren't managed by mainWindow when at FullScreen
videoWindow()->move( 0, 0 ); videoWindow()->move( 0, 0 );
videoWindow()->resize( ((TQWidget*)o)->size() ); videoWindow()->resize( ((TQWidget*)o)->size() );
videoWindow()->lower();
} }
if (o == m_toolbar) if (o == m_toolbar)
@ -580,14 +592,12 @@ MainWindow::fullScreenToggled( bool isFullScreen )
statusBar()->setHidden( isFullScreen ); statusBar()->setHidden( isFullScreen );
setMouseTracking( isFullScreen ); /// @see mouseMoveEvent() setMouseTracking( isFullScreen ); /// @see mouseMoveEvent()
m_widgetStack->setMouseTracking(isFullScreen);
if (isFullScreen) if (isFullScreen)
s_handler = new FullScreenToolBarHandler( this ); s_handler = new FullScreenToolBarHandler( this );
else else
delete s_handler; delete s_handler;
// prevent videoWindow() moving around when mouse moves
setCentralWidget( isFullScreen ? nullptr : videoWindow() );
} }
void void

@ -11,11 +11,14 @@ class KURL;
class TQLabel; class TQLabel;
class TQPopupMenu; class TQPopupMenu;
class TQSlider; class TQSlider;
class TQWidgetStack;
class VolumeAction; class VolumeAction;
namespace Codeine namespace Codeine
{ {
class AudioView;
class MainWindow : public TDEMainWindow class MainWindow : public TDEMainWindow
{ {
TQ_OBJECT TQ_OBJECT
@ -66,6 +69,8 @@ namespace Codeine
TQLabel *m_timeLabel; TQLabel *m_timeLabel;
TQLabel *m_titleLabel; TQLabel *m_titleLabel;
TQWidget *m_analyzer; TQWidget *m_analyzer;
AudioView *m_audioView;
TQWidgetStack *m_widgetStack;
VolumeAction *m_volumeAction; VolumeAction *m_volumeAction;
//undefined //undefined

@ -13,6 +13,8 @@
#include <tqlabel.h> #include <tqlabel.h>
#include <tqpopupmenu.h> #include <tqpopupmenu.h>
#include <tqslider.h> #include <tqslider.h>
#include <tqwidgetstack.h>
#include "audioView.h"
#include "theStream.h" #include "theStream.h"
#include "videoSettings.h" //FIXME unfortunate #include "videoSettings.h" //FIXME unfortunate
#include "xineEngine.h" #include "xineEngine.h"
@ -104,8 +106,18 @@ MainWindow::engineStateChanged( Engine::State state )
/// update statusBar /// update statusBar
{ {
using namespace Engine; using namespace Engine;
m_analyzer->setShown( state & (Playing | Paused) && TheStream::hasAudio() ); m_analyzer->setShown(state & (Playing | Paused) && (TheStream::hasVideo() && TheStream::hasAudio()));
m_timeLabel->setShown( state & (Playing | Paused) ); m_timeLabel->setShown(state & (Playing | Paused));
}
// Update the current widget shown.
if (TheStream::hasVideo() || (state & (Engine::Empty)))
{
m_widgetStack->raiseWidget(videoWindow());
}
else if (TheStream::hasAudio())
{
m_widgetStack->raiseWidget(m_audioView);
} }

Loading…
Cancel
Save