root/branches/jackMidi/gui/src/PatternEditor/DrumPatternEditor.cpp @ 826

Revision 826, 19.2 KB (checked in by gabriel@…, 4 years ago)

Merge rev 594:682 from trunk

Conflicts:

Sconstruct

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23#include "DrumPatternEditor.h"
24#include "PatternEditorPanel.h"
25#include "NotePropertiesRuler.h"
26
27#include <hydrogen/globals.h>
28#include <hydrogen/Song.h>
29#include <hydrogen/hydrogen.h>
30#include <hydrogen/Preferences.h>
31#include <hydrogen/event_queue.h>
32#include <hydrogen/instrument.h>
33#include <hydrogen/Pattern.h>
34#include <hydrogen/note.h>
35#include <hydrogen/audio_engine.h>
36
37#include "../HydrogenApp.h"
38#include "../Mixer/Mixer.h"
39#include "../Skin.h"
40
41#include <cassert>
42#include <algorithm>
43
44#include <QtGui>
45
46using namespace std;
47using namespace H2Core;
48
49DrumPatternEditor::DrumPatternEditor(QWidget* parent, PatternEditorPanel *panel)
50 : QWidget( parent )
51 , Object( "DrumPatternEditor" )
52 , m_nResolution( 8 )
53 , m_bUseTriplets( false )
54 , m_bRightBtnPressed( false )
55 , m_pDraggedNote( NULL )
56 , m_pPattern( NULL )
57 , m_pPatternEditorPanel( panel )
58{
59        //setAttribute(Qt::WA_NoBackground);
60        setFocusPolicy(Qt::ClickFocus);
61
62        m_nGridWidth = Preferences::getInstance()->getPatternEditorGridWidth();
63        m_nGridHeight = Preferences::getInstance()->getPatternEditorGridHeight();
64
65        unsigned nEditorWidth = 20 + m_nGridWidth * ( MAX_NOTES * 4 );
66        m_nEditorHeight = m_nGridHeight * MAX_INSTRUMENTS;
67
68        resize( nEditorWidth, m_nEditorHeight );
69
70        HydrogenApp::getInstance()->addEventListener( this );
71       
72}
73
74
75
76DrumPatternEditor::~DrumPatternEditor()
77{
78}
79
80
81
82void DrumPatternEditor::updateEditor()
83{
84        Hydrogen* engine = Hydrogen::get_instance();
85
86        // check engine state
87        int state = engine->getState();
88        if ( (state != STATE_READY) && (state != STATE_PLAYING) ) {
89                ERRORLOG( "FIXME: skipping pattern editor update (state shoud be READY or PLAYING)" );
90                return;
91        }
92
93        Hydrogen *pEngine = Hydrogen::get_instance();
94        PatternList *pPatternList = pEngine->getSong()->get_pattern_list();
95        int nSelectedPatternNumber = pEngine->getSelectedPatternNumber();
96        if ( (nSelectedPatternNumber != -1) && ( (uint)nSelectedPatternNumber < pPatternList->get_size() ) ) {
97                m_pPattern = pPatternList->get( nSelectedPatternNumber );
98        }
99        else {
100                m_pPattern = NULL;
101        }
102
103
104        uint nEditorWidth;
105        if ( m_pPattern ) {
106                nEditorWidth = 20 + m_nGridWidth * m_pPattern->get_lenght();
107        }
108        else {
109                nEditorWidth = 20 + m_nGridWidth * MAX_NOTES;
110        }
111        resize( nEditorWidth, height() );
112
113        // redraw all
114        update( 0, 0, width(), height() );
115}
116
117
118
119int DrumPatternEditor::getColumn(QMouseEvent *ev)
120{
121        int nBase;
122        if (m_bUseTriplets) {
123                nBase = 3;
124        }
125        else {
126                nBase = 4;
127        }
128        int nWidth = (m_nGridWidth * 4 * MAX_NOTES) / (nBase * m_nResolution);
129
130        int x = ev->x();
131        int nColumn;
132        nColumn = x - 20 + (nWidth / 2);
133        nColumn = nColumn / nWidth;
134        nColumn = (nColumn * 4 * MAX_NOTES) / (nBase * m_nResolution);
135        return nColumn;
136}
137
138
139
140void DrumPatternEditor::mousePressEvent(QMouseEvent *ev)
141{
142        if ( m_pPattern == NULL ) {
143                return;
144        }
145        Song *pSong = Hydrogen::get_instance()->getSong();
146        int nInstruments = pSong->get_instrument_list()->get_size();
147
148        int row = (int)( ev->y()  / (float)m_nGridHeight);
149        if (row >= nInstruments) {
150                return;
151        }
152
153        int nColumn = getColumn( ev );
154
155        if ( nColumn >= (int)m_pPattern->get_lenght() ) {
156                update( 0, 0, width(), height() );
157                return;
158        }
159        Instrument *pSelectedInstrument = pSong->get_instrument_list()->get( row );
160
161        if (ev->button() == Qt::LeftButton ) {
162                m_bRightBtnPressed = false;
163                AudioEngine::get_instance()->lock( "DrumPatternEditor::mousePressEvent" );      // lock the audio engine
164
165                bool bNoteAlreadyExist = false;
166                std::multimap <int, Note*>::iterator pos;
167                for ( pos = m_pPattern->note_map.lower_bound( nColumn ); pos != m_pPattern->note_map.upper_bound( nColumn ); ++pos ) {
168                        Note *pNote = pos->second;
169                        assert( pNote );
170                        if ( pNote->get_instrument() == pSelectedInstrument ) {
171                                // the note exists...remove it!
172                                bNoteAlreadyExist = true;
173                                delete pNote;
174                                m_pPattern->note_map.erase( pos );
175                                break;
176                        }
177                }
178
179                if ( bNoteAlreadyExist == false ) {
180                        // create the new note
181                        const unsigned nPosition = nColumn;
182                        const float fVelocity = 0.8f;
183                        const float fPan_L = 0.5f;
184                        const float fPan_R = 0.5f;
185                        const int nLength = -1;
186                        const float fPitch = 0.0f;
187                        Note *pNote = new Note( pSelectedInstrument, nPosition, fVelocity, fPan_L, fPan_R, nLength, fPitch);
188                        m_pPattern->note_map.insert( std::make_pair( nPosition, pNote ) );
189
190                        // hear note
191                        Preferences *pref = Preferences::getInstance();
192                        if ( pref->getHearNewNotes() ) {
193                                Note *pNote2 = new Note( pSelectedInstrument, 0, fVelocity, fPan_L, fPan_R, nLength, fPitch);
194                                AudioEngine::get_instance()->get_sampler()->note_on(pNote2);
195                        }
196                }
197                pSong->__is_modified = true;
198                AudioEngine::get_instance()->unlock(); // unlock the audio engine
199        }
200        else if (ev->button() == Qt::RightButton ) {
201                m_bRightBtnPressed = true;
202                m_pDraggedNote = NULL;
203
204                int nRealColumn = (ev->x() - 20) /  static_cast<float>(m_nGridWidth);
205
206                AudioEngine::get_instance()->lock( "DrumPatternEditor::mousePressEvent" );
207
208                std::multimap <int, Note*>::iterator pos;
209                for ( pos = m_pPattern->note_map.lower_bound( nColumn ); pos != m_pPattern->note_map.upper_bound( nColumn ); ++pos ) {
210                        Note *pNote = pos->second;
211                        assert( pNote );
212
213                        if ( pNote->get_instrument() == pSelectedInstrument ) {
214                                m_pDraggedNote = pNote;
215                                break;
216                        }
217                }
218                if ( !m_pDraggedNote ) {
219                        for ( pos = m_pPattern->note_map.lower_bound( nRealColumn ); pos != m_pPattern->note_map.upper_bound( nRealColumn ); ++pos ) {
220                                Note *pNote = pos->second;
221                                assert( pNote );
222
223                                if ( pNote->get_instrument() == pSelectedInstrument ) {
224                                        m_pDraggedNote = pNote;
225                                        break;
226                                }
227                        }
228                }
229                // potrei essere sulla coda di una nota precedente..
230                for ( int nCol = 0; nCol < nRealColumn; ++nCol ) {
231                        if ( m_pDraggedNote ) break;
232                        for ( pos = m_pPattern->note_map.lower_bound( nCol ); pos != m_pPattern->note_map.upper_bound( nCol ); ++pos ) {
233                                Note *pNote = pos->second;
234                                assert( pNote );
235
236                                if ( pNote->get_instrument() == pSelectedInstrument ) {
237                                        m_pDraggedNote = pNote;
238                                        break;
239                                }
240                        }
241                }
242                AudioEngine::get_instance()->unlock();
243        }
244
245        // update the selected line
246        int nSelectedInstrument = Hydrogen::get_instance()->getSelectedInstrumentNumber();
247        if (nSelectedInstrument != row) {
248                Hydrogen::get_instance()->setSelectedInstrumentNumber( row );
249        }
250        else {
251                update( 0, 0, width(), height() );
252                m_pPatternEditorPanel->getVelocityEditor()->updateEditor();
253                m_pPatternEditorPanel->getPanEditor()->updateEditor();
254                m_pPatternEditorPanel->getLeadLagEditor()->updateEditor();
255        }
256}
257
258
259
260void DrumPatternEditor::mouseReleaseEvent(QMouseEvent *ev)
261{
262        UNUSED( ev );
263        setCursor( QCursor( Qt::ArrowCursor ) );
264
265        if (m_pPattern == NULL) {
266                return;
267        }
268}
269
270
271
272void DrumPatternEditor::mouseMoveEvent(QMouseEvent *ev)
273{
274        if (m_pPattern == NULL) {
275                return;
276        }
277
278        int row = MAX_INSTRUMENTS - 1 - (ev->y()  / (int)m_nGridHeight);
279        if (row >= MAX_INSTRUMENTS) {
280                return;
281        }
282
283        if (m_bRightBtnPressed && m_pDraggedNote ) {
284                int nTickColumn = getColumn( ev );
285
286                AudioEngine::get_instance()->lock("DrumPatternEditor::mouseMoveEvent"); // lock the audio engine
287                int nLen = nTickColumn - (int)m_pDraggedNote->get_position();
288
289                if (nLen <= 0) {
290                        nLen = -1;
291                }
292                m_pDraggedNote->set_lenght( nLen );
293
294                Hydrogen::get_instance()->getSong()->__is_modified = true;
295                AudioEngine::get_instance()->unlock(); // unlock the audio engine
296
297                //__draw_pattern();
298                update( 0, 0, width(), height() );
299                m_pPatternEditorPanel->getVelocityEditor()->updateEditor();
300                m_pPatternEditorPanel->getPanEditor()->updateEditor();
301                m_pPatternEditorPanel->getLeadLagEditor()->updateEditor();
302        }
303
304}
305
306
307
308void DrumPatternEditor::keyPressEvent (QKeyEvent *ev)
309{
310        ev->ignore();
311}
312
313
314
315///
316/// Draws a pattern
317///
318void DrumPatternEditor::__draw_pattern(QPainter& painter)
319{
320        const UIStyle *pStyle = Preferences::getInstance()->getDefaultUIStyle();
321        const QColor selectedRowColor( pStyle->m_patternEditor_selectedRowColor.getRed(), pStyle->m_patternEditor_selectedRowColor.getGreen(), pStyle->m_patternEditor_selectedRowColor.getBlue() );
322
323        __create_background( painter );
324
325        if (m_pPattern == NULL) {
326                return;
327        }
328
329        int nNotes = m_pPattern->get_lenght();
330        int nSelectedInstrument = Hydrogen::get_instance()->getSelectedInstrumentNumber();
331        Song *pSong = Hydrogen::get_instance()->getSong();
332
333        InstrumentList * pInstrList = pSong->get_instrument_list();
334
335       
336
337        if ( m_nEditorHeight != (int)( m_nGridHeight * pInstrList->get_size() ) ) {
338                // the number of instruments is changed...recreate all
339                m_nEditorHeight = m_nGridHeight * pInstrList->get_size();
340                resize( width(), m_nEditorHeight );
341        }
342
343        for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) {
344                uint y = m_nGridHeight * nInstr;
345                if ( nInstr == (uint)nSelectedInstrument ) {    // selected instrument
346                        painter.fillRect( 0, y + 1, (20 + nNotes * m_nGridWidth), m_nGridHeight - 1, selectedRowColor );
347                }
348        }
349
350
351        // draw the grid
352        __draw_grid( painter );
353       
354
355        /*
356                BUGFIX
357               
358                if m_pPattern is not renewed every time we draw a note,
359                hydrogen will crash after you save a song and create a new one.
360                -smoors
361        */
362        Hydrogen *pEngine = Hydrogen::get_instance();
363        PatternList *pPatternList = pEngine->getSong()->get_pattern_list();
364        int nSelectedPatternNumber = pEngine->getSelectedPatternNumber();
365        if ( (nSelectedPatternNumber != -1) && ( (uint)nSelectedPatternNumber < pPatternList->get_size() ) ) {
366                m_pPattern = pPatternList->get( nSelectedPatternNumber );
367        }
368        else {
369                m_pPattern = NULL;
370        }
371        // ~ FIX
372
373
374
375        if( m_pPattern->note_map.size() == 0) return;
376
377        std::multimap <int, Note*>::iterator pos;
378        for ( pos = m_pPattern->note_map.begin(); pos != m_pPattern->note_map.end(); pos++ ) {
379                Note *note = pos->second;
380                assert( note );
381                __draw_note( note, painter );
382        }
383}
384
385
386///
387/// Draws a note
388///
389void DrumPatternEditor::__draw_note( Note *note, QPainter& p )
390{
391        static const UIStyle *pStyle = Preferences::getInstance()->getDefaultUIStyle();
392        static const QColor noteColor( pStyle->m_patternEditor_noteColor.getRed(), pStyle->m_patternEditor_noteColor.getGreen(), pStyle->m_patternEditor_noteColor.getBlue() );
393
394        p.setRenderHint( QPainter::Antialiasing );
395
396        int nInstrument = -1;
397        InstrumentList * pInstrList = Hydrogen::get_instance()->getSong()->get_instrument_list();
398        for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) {
399                Instrument *pInstr = pInstrList->get( nInstr );
400                if ( pInstr == note->get_instrument() ) {
401                        nInstrument = nInstr;
402                        break;
403                }
404        }
405        if ( nInstrument == -1 ) {
406                ERRORLOG( "Instrument not found..skipping note" );
407                return;
408        }
409
410        uint pos = note->get_position();
411
412        p.setPen( noteColor );
413
414        if ( note->get_lenght() == -1 ) {       // trigger note
415                uint x_pos = 20 + (pos * m_nGridWidth);// - m_nGridWidth / 2.0;
416
417                uint y_pos = ( nInstrument * m_nGridHeight) + (m_nGridHeight / 2) - 3;
418
419                // draw the "dot"
420                p.drawLine(x_pos, y_pos, x_pos + 3, y_pos + 3);         // A
421                p.drawLine(x_pos, y_pos, x_pos - 3, y_pos + 3);         // B
422                p.drawLine(x_pos, y_pos + 6, x_pos + 3, y_pos + 3);     // C
423                p.drawLine(x_pos - 3, y_pos + 3, x_pos, y_pos + 6);     // D
424
425                p.drawLine(x_pos, y_pos + 1, x_pos + 2, y_pos + 3);
426                p.drawLine(x_pos, y_pos + 1, x_pos - 2, y_pos + 3);
427                p.drawLine(x_pos, y_pos + 5, x_pos + 2, y_pos + 3);
428                p.drawLine(x_pos - 2, y_pos + 3, x_pos, y_pos + 5);
429
430                p.drawLine(x_pos, y_pos + 2, x_pos + 1, y_pos + 3);
431                p.drawLine(x_pos, y_pos + 2, x_pos - 1, y_pos + 3);
432                p.drawLine(x_pos, y_pos + 4, x_pos + 1, y_pos + 3);
433                p.drawLine(x_pos - 1, y_pos + 3, x_pos, y_pos + 4);
434        }
435        else {
436                uint x = 20 + (pos * m_nGridWidth);
437                int w = m_nGridWidth * note->get_lenght();
438                w = w - 1;      // lascio un piccolo spazio tra una nota ed un altra
439
440                int y = (int) ( ( nInstrument ) * m_nGridHeight  + (m_nGridHeight / 100.0 * 30.0) );
441                int h = (int) (m_nGridHeight - ((m_nGridHeight / 100.0 * 30.0) * 2.0) );
442
443                p.fillRect( x, y + 1, w, h + 1, QColor(100, 100, 200) );        /// \todo: definire questo colore nelle preferenze
444                p.drawRect( x, y + 1, w, h + 1 );
445        }
446}
447
448
449
450
451void DrumPatternEditor::__draw_grid( QPainter& p )
452{
453        static const UIStyle *pStyle = Preferences::getInstance()->getDefaultUIStyle();
454        static const QColor res_1( pStyle->m_patternEditor_line1Color.getRed(), pStyle->m_patternEditor_line1Color.getGreen(), pStyle->m_patternEditor_line1Color.getBlue() );
455        static const QColor res_2( pStyle->m_patternEditor_line2Color.getRed(), pStyle->m_patternEditor_line2Color.getGreen(), pStyle->m_patternEditor_line2Color.getBlue() );
456        static const QColor res_3( pStyle->m_patternEditor_line3Color.getRed(), pStyle->m_patternEditor_line3Color.getGreen(), pStyle->m_patternEditor_line3Color.getBlue() );
457        static const QColor res_4( pStyle->m_patternEditor_line4Color.getRed(), pStyle->m_patternEditor_line4Color.getGreen(), pStyle->m_patternEditor_line4Color.getBlue() );
458        static const QColor res_5( pStyle->m_patternEditor_line5Color.getRed(), pStyle->m_patternEditor_line5Color.getGreen(), pStyle->m_patternEditor_line5Color.getBlue() );
459
460        // vertical lines
461        p.setPen( QPen( res_1, 0, Qt::DotLine ) );
462
463        int nBase;
464        if (m_bUseTriplets) {
465                nBase = 3;
466        }
467        else {
468                nBase = 4;
469        }
470
471        int n4th = 4 * MAX_NOTES / (nBase * 4);
472        int n8th = 4 * MAX_NOTES / (nBase * 8);
473        int n16th = 4 * MAX_NOTES / (nBase * 16);
474        int n32th = 4 * MAX_NOTES / (nBase * 32);
475        int n64th = 4 * MAX_NOTES / (nBase * 64);
476
477        int nNotes = MAX_NOTES;
478        if ( m_pPattern ) {
479                nNotes = m_pPattern->get_lenght();
480        }
481        if (!m_bUseTriplets) {
482                for ( int i = 0; i < nNotes + 1; i++ ) {
483                        uint x = 20 + i * m_nGridWidth;
484
485                        if ( (i % n4th) == 0 ) {
486                                if (m_nResolution >= 4) {
487                                        p.setPen( QPen( res_1, 0 ) );
488                                        p.drawLine(x, 1, x, m_nEditorHeight - 1);
489                                }
490                        }
491                        else if ( (i % n8th) == 0 ) {
492                                if (m_nResolution >= 8) {
493                                        p.setPen( QPen( res_2, 0 ) );
494                                        p.drawLine(x, 1, x, m_nEditorHeight - 1);
495                                }
496                        }
497                        else if ( (i % n16th) == 0 ) {
498                                if (m_nResolution >= 16) {
499                                        p.setPen( QPen( res_3, 0 ) );
500                                        p.drawLine(x, 1, x, m_nEditorHeight - 1);
501                                }
502                        }
503                        else if ( (i % n32th) == 0 ) {
504                                if (m_nResolution >= 32) {
505                                        p.setPen( QPen( res_4, 0 ) );
506                                        p.drawLine(x, 1, x, m_nEditorHeight - 1);
507                                }
508                        }
509                        else if ( (i % n64th) == 0 ) {
510                                if (m_nResolution >= 64) {
511                                        p.setPen( QPen( res_5, 0 ) );
512                                        p.drawLine(x, 1, x, m_nEditorHeight - 1);
513                                }
514                        }
515                }
516        }
517        else {  // Triplets
518                uint nCounter = 0;
519                int nSize = 4 * MAX_NOTES / (nBase * m_nResolution);
520
521                for ( int i = 0; i < nNotes + 1; i++ ) {
522                        uint x = 20 + i * m_nGridWidth;
523
524                        if ( (i % nSize) == 0) {
525                                if ((nCounter % 3) == 0) {
526                                        p.setPen( QPen( res_1, 0 ) );
527                                }
528                                else {
529                                        p.setPen( QPen( res_3, 0 ) );
530                                }
531                                p.drawLine(x, 1, x, m_nEditorHeight - 1);
532                                nCounter++;
533                        }
534                }
535        }
536
537
538        // fill the first half of the rect with a solid color
539        static const QColor backgroundColor( pStyle->m_patternEditor_backgroundColor.getRed(), pStyle->m_patternEditor_backgroundColor.getGreen(), pStyle->m_patternEditor_backgroundColor.getBlue() );
540        static const QColor selectedRowColor( pStyle->m_patternEditor_selectedRowColor.getRed(), pStyle->m_patternEditor_selectedRowColor.getGreen(), pStyle->m_patternEditor_selectedRowColor.getBlue() );
541        int nSelectedInstrument = Hydrogen::get_instance()->getSelectedInstrumentNumber();
542        Song *pSong = Hydrogen::get_instance()->getSong();
543        int nInstruments = pSong->get_instrument_list()->get_size();
544        for ( uint i = 0; i < (uint)nInstruments; i++ ) {
545                uint y = m_nGridHeight * i + 1;
546                if ( i == (uint)nSelectedInstrument ) {
547                        p.fillRect( 0, y, (20 + nNotes * m_nGridWidth), (int)( m_nGridHeight * 0.7 ), selectedRowColor );
548                }
549                else {
550                        p.fillRect( 0, y, (20 + nNotes * m_nGridWidth), (int)( m_nGridHeight * 0.7 ), backgroundColor );
551                }
552        }
553
554}
555
556
557void DrumPatternEditor::__create_background( QPainter& p)
558{
559        static const UIStyle *pStyle = Preferences::getInstance()->getDefaultUIStyle();
560        static const QColor backgroundColor( pStyle->m_patternEditor_backgroundColor.getRed(), pStyle->m_patternEditor_backgroundColor.getGreen(), pStyle->m_patternEditor_backgroundColor.getBlue() );
561        static const QColor alternateRowColor( pStyle->m_patternEditor_alternateRowColor.getRed(), pStyle->m_patternEditor_alternateRowColor.getGreen(), pStyle->m_patternEditor_alternateRowColor.getBlue() );
562        static const QColor lineColor( pStyle->m_patternEditor_lineColor.getRed(), pStyle->m_patternEditor_lineColor.getGreen(), pStyle->m_patternEditor_lineColor.getBlue() );
563
564        int nNotes = MAX_NOTES;
565        if ( m_pPattern ) {
566                nNotes = m_pPattern->get_lenght();
567        }
568
569        Song *pSong = Hydrogen::get_instance()->getSong();
570        int nInstruments = pSong->get_instrument_list()->get_size();
571
572        if ( m_nEditorHeight != (int)( m_nGridHeight * nInstruments ) ) {
573                // the number of instruments is changed...recreate all
574                m_nEditorHeight = m_nGridHeight * nInstruments;
575                resize( width(), m_nEditorHeight );
576        }
577
578        p.fillRect(0, 0, 20 + nNotes * m_nGridWidth, height(), backgroundColor);
579        for ( uint i = 0; i < (uint)nInstruments; i++ ) {
580                uint y = m_nGridHeight * i;
581                if ( ( i % 2) != 0) {
582                        p.fillRect( 0, y, (20 + nNotes * m_nGridWidth), m_nGridHeight, alternateRowColor );
583                }
584        }
585
586        // horizontal lines
587        p.setPen( lineColor );
588        for ( uint i = 0; i < (uint)nInstruments; i++ ) {
589                uint y = m_nGridHeight * i + m_nGridHeight;
590                p.drawLine( 0, y, (20 + nNotes * m_nGridWidth), y);
591        }
592
593        p.drawLine( 0, m_nEditorHeight, (20 + nNotes * m_nGridWidth), m_nEditorHeight );
594}
595
596
597
598void DrumPatternEditor::paintEvent( QPaintEvent* /*ev*/ )
599{
600        //INFOLOG( "paint" );
601        //QWidget::paintEvent(ev);
602       
603        QPainter painter( this );
604        __draw_pattern( painter );
605}
606
607
608
609
610
611
612void DrumPatternEditor::showEvent ( QShowEvent *ev )
613{
614        UNUSED( ev );
615        updateEditor();
616}
617
618
619
620void DrumPatternEditor::hideEvent ( QHideEvent *ev )
621{
622        UNUSED( ev );
623}
624
625
626
627void DrumPatternEditor::setResolution(uint res, bool bUseTriplets)
628{
629        this->m_nResolution = res;
630        this->m_bUseTriplets = bUseTriplets;
631
632        // redraw all
633        update( 0, 0, width(), height() );
634        m_pPatternEditorPanel->getVelocityEditor()->updateEditor();
635        m_pPatternEditorPanel->getPanEditor()->updateEditor();
636        m_pPatternEditorPanel->getLeadLagEditor()->updateEditor();
637        /// \todo [DrumPatternEditor::setResolution] aggiornare la risoluzione del Ruler in alto."
638}
639
640
641void DrumPatternEditor::zoom_in()
642{
643        if (m_nGridWidth >= 3){
644                m_nGridWidth *= 2;
645        }else
646        {
647                m_nGridWidth *= 1.5;
648        }
649        updateEditor();
650}
651
652
653
654void DrumPatternEditor::zoom_out()
655{
656        if ( m_nGridWidth > 1.5 ) {
657                if (m_nGridWidth > 3){
658                        m_nGridWidth /= 2;
659                }else
660                {
661                        m_nGridWidth /= 1.5;
662                }
663                updateEditor();
664        }
665}
666
667
668void DrumPatternEditor::selectedInstrumentChangedEvent()
669{
670        update( 0, 0, width(), height() );
671}
672
673
674/// This method is called from another thread (audio engine)
675void DrumPatternEditor::patternModifiedEvent()
676{
677        update( 0, 0, width(), height() );
678}
679
680
681void DrumPatternEditor::patternChangedEvent()
682{
683        updateEditor();
684}
685
686void DrumPatternEditor::selectedPatternChangedEvent()
687{
688        //cout << "selected pattern changed EVENT" << endl;
689        updateEditor();
690}
691
692
693
Note: See TracBrowser for help on using the browser.