hydrogen 1.2.3
DetailWaveDisplay.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#include <core/Basics/Sample.h>
24#include <core/Basics/Song.h>
26using namespace H2Core;
27
28#include "DetailWaveDisplay.h"
29#include "../Skin.h"
30
32 : QWidget( pParent )
33 , m_sSampleName( "" )
34 , m_pPeakDatal( nullptr )
35 , m_pPeakDatar( nullptr )
36{
37// setAttribute(Qt::WA_OpaquePaintEvent);
38
39 //
40 int w = 180;
41 int h = 265;
42 resize( w, h );
43
44 bool ok = m_background.load( Skin::getImagePath() + "/waveDisplay/detailsamplewavedisplay.png" );
45 if( ok == false ){
46 ERRORLOG( "Error loading pixmap" );
47 }
48
51 m_pZoomFactor = 1;
52
53}
54
55
56
57
59{
60 //INFOLOG( "DESTROY" );
61 delete[] m_pPeakDatal;
62 delete[] m_pPeakDatar;
63}
64
65
66void DetailWaveDisplay::setDetailSamplePosition( unsigned posi, float zoomfactor, QString type)
67{
69 m_pZoomFactor = zoomfactor;
70 m_pType = type;
71 update();
72}
73
74void DetailWaveDisplay::paintEvent(QPaintEvent *ev)
75{
76 QPainter painter( this );
77 painter.setRenderHint( QPainter::Antialiasing );
78 painter.drawPixmap( ev->rect(), m_background, ev->rect() );
79
80 painter.setPen( QColor( 230, 230, 230 ) );
81 int VCenterl = height() / 4;
82 int VCenterr = height() / 4 + height() / 2;
83
84// int imagedetailframes = m_pnormalimagedetailframes / m_pzoomFactor;
86
87 for ( int x = 0; x < width() ; x++ ) {
88 if ( (startpos) > 0 ){
89 painter.drawLine( x, (-m_pPeakDatal[startpos -1] *m_pZoomFactor) +VCenterl, x, (-m_pPeakDatal[startpos ] *m_pZoomFactor)+VCenterl );
90 painter.drawLine( x, (-m_pPeakDatar[startpos -1] *m_pZoomFactor) +VCenterr, x, (-m_pPeakDatar[startpos ] *m_pZoomFactor)+VCenterr );
91 //ERRORLOG( QString("startpos: %1").arg(startpos) )
92 }
93 else
94 {
95 painter.drawLine( x, 0 +VCenterl, x, 0+VCenterl );
96 painter.drawLine( x, 0 +VCenterr, x, 0+VCenterr );
97 }
98 startpos++;
99
100 }
101
102
103 painter.setPen( QPen( QColor( 255, 255, 255 ), 1, Qt::DotLine ) );
104 painter.drawLine( 0, VCenterl, width(),VCenterl );
105 painter.drawLine( 0, VCenterr, width(),VCenterr );
106 QColor _color;
107 if ( m_pType == "Start" ) {
108 _color = QColor( 32, 173, 0 );
109 } else if ( m_pType == "Loop" ) {
110 _color = QColor( 93, 170, 254 );
111 } else if ( m_pType == "End" ) {
112 _color = QColor( 217, 68, 0 );
113 } else {
114 _color = QColor( 255, 255, 255 );
115 }
116
117 painter.setPen( QPen( _color, 1, Qt::SolidLine ) );
118 painter.drawLine( 90, 0, 90,265 );
119}
120
121
122
123void DetailWaveDisplay::updateDisplay( QString filename )
124{
125
126 auto pNewSample = Sample::load( filename );
127
128 if ( pNewSample != nullptr ) {
129
130 int mSampleLength = pNewSample->get_frames();
131
132 m_pPeakDatal = new int[ mSampleLength + m_pNormalImageDetailFrames /2 ];
133 m_pPeakDatar = new int[ mSampleLength + m_pNormalImageDetailFrames /2 ];
134
135 for ( int i = 0 ; i < mSampleLength + m_pNormalImageDetailFrames /2 ; i++){
136 m_pPeakDatal[ i ] = 0;
137 m_pPeakDatar[ i ] = 0;
138 }
139
140 float fGain = height() / 4.0 * 1.0;
141
142 auto pSampleDatal = pNewSample->get_data_l();
143 auto pSampleDatar = pNewSample->get_data_r();
144
145 for ( int i = 0; i < mSampleLength; i++ ){
146 m_pPeakDatal[ i ] = static_cast<int>( pSampleDatal[ i ] * fGain );
147 m_pPeakDatar[ i ] = static_cast<int>( pSampleDatar[ i ] * fGain );
148 }
149
150
151 }
152}
153
154
155
#define ERRORLOG(x)
Definition Object.h:239
DetailWaveDisplay(QWidget *pParent)
void setDetailSamplePosition(unsigned posi, float zoomfactor, QString type)
void updateDisplay(QString filename)
virtual void paintEvent(QPaintEvent *ev) override
static std::shared_ptr< Sample > load(const QString &filepath, const License &license=License())
Definition Sample.cpp:136
static QString getImagePath()
Definition Skin.h:36