summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/muse/midiedit/midicmd.cpp
blob: bb6b19728fde910fb72fba648b2f4fcf8f3c9596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//=============================================================================
//  MusE
//  Linux Music Editor
//  $Id:$
//
//  Copyright (C) 2002-2006 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#include "midicmd.h"
#include "song.h"
#include "gatetime.h"
#include "velocity.h"
#include "audio.h"
#include "midieditor.h"
#include "widgets/tb1.h"

//==========================================================
//     class MidiCmd is an attempt to formalize the 
//     interface between midi command code and MusE.
//     Maybe this can be extended to an specialized
//     plugin interface
//==========================================================

//---------------------------------------------------------
//   MidiCmdDialog
//---------------------------------------------------------

MidiCmdDialog::MidiCmdDialog()
   : QDialog()
      {
      QWidget* rangeWidget = new QWidget;
      mc.setupUi(rangeWidget);
      layout = new QVBoxLayout;
      setLayout(layout);
      layout->addWidget(rangeWidget);
      rangeGroup = new QButtonGroup(this);
      rangeGroup->setExclusive(true);
      rangeGroup->addButton(mc.allEventsButton,      RANGE_ALL);
      rangeGroup->addButton(mc.selectedEventsButton, RANGE_SELECTED);
      rangeGroup->addButton(mc.loopedEventsButton,   RANGE_LOOPED);
      rangeGroup->addButton(mc.selectedLoopedButton, RANGE_SELECTED | RANGE_LOOPED);
      mc.allEventsButton->setChecked(true);
      }

//---------------------------------------------------------
//   setRange
//---------------------------------------------------------

void MidiCmdDialog::setRange(int id)
      {
      if (rangeGroup->button(id))
            rangeGroup->button(id)->setChecked(true);
      else
            printf("setRange: not button %d!\n", id);
      }

//---------------------------------------------------------
//   accept
//---------------------------------------------------------

void MidiCmdDialog::accept()
      {
      _range = rangeGroup->checkedId();
      QDialog::accept();
      }

//---------------------------------------------------------
//   MidiCmd
//---------------------------------------------------------

MidiCmd::MidiCmd(MidiEditor* e)
      {
      editor = e;      
      }

//---------------------------------------------------------
//   processEvents
//---------------------------------------------------------

void MidiCmd::processEvents(CItemList* items)
      {
      MidiCmdDialog* dialog = guiDialog();
      range = editor->applyTo();
      dialog->setRange(range);
      bool rv = dialog->exec();
      if (!rv)
            return;
      range = dialog->range();        // all, selected, looped, sel+loop
      editor->setApplyTo(range);
      
      modified = 0;
      song->startUndo();
      process(items);
      song->endUndo(modified);
      }

//---------------------------------------------------------
//   eventInRange
//---------------------------------------------------------

bool MidiCmd::itemInRange(CItem* item)
      {
      unsigned tick = item->event.tick();
      bool selected = item->isSelected();
      bool inLoop   = (tick >= song->lpos()) && (tick < song->rpos());
      return (
            (range == 0)
         || (range == 1 && selected)
         || (range == 2 && inLoop)
         || (range == 3 && selected && inLoop)
         );
      }

//---------------------------------------------------------
//   changeEvent
//---------------------------------------------------------

void MidiCmd::changeEvent(Event oldEvent, Event newEvent, Part* part)
      {
      audio->msgChangeEvent(oldEvent, newEvent, part, false);
      modified = SC_EVENT_MODIFIED;
      }