DelayControlsDialog.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * delaycontrolsdialog.cpp - definition of DelayControlsDialog class.
  3. *
  4. * Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (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 GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include "DelayControlsDialog.h"
  25. #include "DelayControls.h"
  26. #include "embed.h"
  27. #include "TempoSyncKnob.h"
  28. #include "../Eq/EqFader.h"
  29. #include <QMouseEvent>
  30. #include <QPainter>
  31. DelayControlsDialog::DelayControlsDialog( DelayControls *controls ) :
  32. EffectControlDialog( controls )
  33. {
  34. setAutoFillBackground( true );
  35. QPalette pal;
  36. pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
  37. setPalette( pal );
  38. setFixedSize( 300, 208 );
  39. TempoSyncKnob* sampleDelayKnob = new TempoSyncKnob( knobBright_26, this );
  40. sampleDelayKnob->move( 10,14 );
  41. sampleDelayKnob->setVolumeKnob( false );
  42. sampleDelayKnob->setModel( &controls->m_delayTimeModel );
  43. sampleDelayKnob->setLabel( tr( "DELAY" ) );
  44. sampleDelayKnob->setHintText( tr( "Delay time" ) + " ", " s" );
  45. Knob * feedbackKnob = new Knob( knobBright_26, this );
  46. feedbackKnob->move( 11, 58 );
  47. feedbackKnob->setVolumeKnob( true) ;
  48. feedbackKnob->setModel( &controls->m_feedbackModel);
  49. feedbackKnob->setLabel( tr( "FDBK" ) );
  50. feedbackKnob->setHintText( tr ( "Feedback amount" ) + " " , "" );
  51. TempoSyncKnob * lfoFreqKnob = new TempoSyncKnob( knobBright_26, this );
  52. lfoFreqKnob->move( 11, 119 );
  53. lfoFreqKnob->setVolumeKnob( false );
  54. lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
  55. lfoFreqKnob->setLabel( tr( "RATE" ) );
  56. lfoFreqKnob->setHintText( tr ( "LFO frequency") + " ", " s" );
  57. TempoSyncKnob * lfoAmtKnob = new TempoSyncKnob( knobBright_26, this );
  58. lfoAmtKnob->move( 11, 159 );
  59. lfoAmtKnob->setVolumeKnob( false );
  60. lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
  61. lfoAmtKnob->setLabel( tr( "AMNT" ) );
  62. lfoAmtKnob->setHintText( tr ( "LFO amount" ) + " " , " s" );
  63. EqFader * outFader = new EqFader( &controls->m_outGainModel,tr( "Out gain" ),
  64. this, &controls->m_outPeakL, &controls->m_outPeakR );
  65. outFader->setMaximumHeight( 196 );
  66. outFader->move( 263, 45 );
  67. outFader->setDisplayConversion( false );
  68. outFader->setHintText( tr( "Gain" ), "dBFS" );
  69. XyPad * pad = new XyPad( this, &controls->m_feedbackModel, &controls->m_delayTimeModel );
  70. pad->resize( 200, 200 );
  71. pad->move( 50, 5 );
  72. }
  73. XyPad::XyPad(QWidget *parent, FloatModel *xModel, FloatModel *yModel) :
  74. QWidget( parent ),
  75. m_xModel( xModel ),
  76. m_yModel( yModel ),
  77. m_acceptInput( false )
  78. {
  79. connect( m_xModel, SIGNAL( dataChanged() ) , this, SLOT( update() ) );
  80. connect( m_yModel, SIGNAL( dataChanged() ) , this, SLOT( update() ) );
  81. }
  82. void XyPad::paintEvent(QPaintEvent *event)
  83. {
  84. QPainter painter( this );
  85. //Draw Frequecy maker lines
  86. painter.setPen( QPen( QColor( 200, 200, 200, 200 ), 8, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) );
  87. painter.setRenderHint( QPainter::Antialiasing, true );
  88. float xRange = m_xModel->maxValue() - m_xModel->minValue();
  89. float xInc = xRange / width();
  90. int xPos = ( m_xModel->value() - m_xModel->minValue() ) / xInc;
  91. float yRange = m_yModel->maxValue() - m_yModel->minValue();
  92. float yInc = yRange / height();
  93. int yPos = ( m_yModel->value() - m_yModel->minValue() ) / yInc;
  94. painter.drawPoint( xPos, yPos );
  95. }
  96. void XyPad::mousePressEvent(QMouseEvent *event)
  97. {
  98. m_acceptInput = true;
  99. }
  100. void XyPad::mouseReleaseEvent(QMouseEvent *event)
  101. {
  102. m_acceptInput = false;
  103. }
  104. void XyPad::mouseMoveEvent(QMouseEvent *event)
  105. {
  106. if( m_acceptInput && (event->x() >= 0) && ( event->x() < width() )
  107. && ( event->y() >= 0) && ( event->y() < height() ) )
  108. {
  109. //set xmodel
  110. float xRange = m_xModel->maxValue() - m_xModel->minValue();
  111. float xInc = xRange / width();
  112. m_xModel->setValue( m_xModel->minValue() + ( event->x() * xInc ) );
  113. //set ymodel
  114. float yRange = m_yModel->maxValue() - m_yModel->minValue();
  115. float yInc = yRange / height();
  116. m_yModel->setValue( m_yModel->minValue() + ( event->y() * yInc ) );
  117. }
  118. }