Use the channel selector to decide which channel to add program changes to.

git-svn-id: svn://localhost/ardour2/branches/3.0@8343 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-12-26 16:19:32 +00:00
parent bc29adf054
commit fd0c45ec97
5 changed files with 39 additions and 45 deletions

View File

@ -4724,7 +4724,7 @@ Editor::insert_program_change ()
MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (*i);
if (mrv) {
if (p >= mrv->region()->first_frame() && p <= mrv->region()->last_frame()) {
mrv->add_program_change (p - mrv->region()->position(), d.channel (), d.program ());
mrv->add_program_change (p - mrv->region()->position(), d.program ());
}
}
}

View File

@ -58,7 +58,6 @@
#include "midi_region_view.h"
#include "midi_streamview.h"
#include "midi_time_axis.h"
#include "midi_time_axis.h"
#include "midi_util.h"
#include "note_player.h"
#include "public_editor.h"
@ -726,7 +725,7 @@ MidiRegionView::create_note_at(double x, double y, double length, bool sh)
MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
MidiStreamView* const view = mtv->midi_view();
double note = midi_stream_view()->y_to_note(y);
double note = view->y_to_note(y);
assert(note >= 0.0);
assert(note <= 127.0);
@ -745,26 +744,7 @@ MidiRegionView::create_note_at(double x, double y, double length, bool sh)
length = frames_to_beats (beats_to_frames (length) - 1);
}
uint16_t chn_mask = mtv->channel_selector().get_selected_channels();
int chn_cnt = 0;
uint8_t channel = 0;
/* pick the highest selected channel, unless all channels are selected,
which is interpreted to mean channel 1 (zero)
*/
for (uint16_t i = 0; i < 16; ++i) {
if (chn_mask & (1<<i)) {
channel = i;
chn_cnt++;
}
}
if (chn_cnt == 16) {
channel = 0;
}
const boost::shared_ptr<NoteType> new_note (new NoteType (channel,
const boost::shared_ptr<NoteType> new_note (new NoteType (get_channel_for_add (),
frames_to_beats(start_frames + _region->start()), length,
(uint8_t)note, 0x40));
@ -1670,10 +1650,10 @@ MidiRegionView::alter_program_change(PCEvent& old_program, const MIDI::Name::Pat
/** @param t Time in frames relative to region position */
void
MidiRegionView::add_program_change (framecnt_t t, uint8_t channel, uint8_t value)
MidiRegionView::add_program_change (framecnt_t t, uint8_t value)
{
boost::shared_ptr<Evoral::Control> control = midi_region()->model()->control (
Evoral::Parameter (MidiPgmChangeAutomation, channel, 0), true
Evoral::Parameter (MidiPgmChangeAutomation, get_channel_for_add (), 0), true
);
assert (control);
@ -3294,3 +3274,32 @@ MidiRegionView::trim_front_ending ()
midi_region()->fix_negative_start ();
}
}
/** @return channel (counted from 0) to add an event to, based on the current setting
* of the channel selector.
*/
uint8_t
MidiRegionView::get_channel_for_add () const
{
MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
uint16_t const chn_mask = mtv->channel_selector().get_selected_channels();
int chn_cnt = 0;
uint8_t channel = 0;
/* pick the highest selected channel, unless all channels are selected,
which is interpreted to mean channel 1 (zero)
*/
for (uint16_t i = 0; i < 16; ++i) {
if (chn_mask & (1<<i)) {
channel = i;
chn_cnt++;
}
}
if (chn_cnt == 16) {
channel = 0;
}
return channel;
}

View File

@ -149,7 +149,7 @@ class MidiRegionView : public RegionView
*/
void alter_program_change(PCEvent& old_program, const MIDI::Name::PatchPrimaryKey& new_patch);
void add_program_change (framecnt_t, uint8_t, uint8_t);
void add_program_change (framecnt_t, uint8_t);
void move_program_change (PCEvent, Evoral::MusicalTime);
void delete_program_change (ArdourCanvas::CanvasProgramChange *);
@ -346,6 +346,8 @@ class MidiRegionView : public RegionView
void add_to_selection (ArdourCanvas::CanvasNoteEvent*);
void remove_from_selection (ArdourCanvas::CanvasNoteEvent*);
uint8_t get_channel_for_add () const;
int8_t _force_channel;
uint16_t _last_channel_selection;
uint8_t _current_range_min;

View File

@ -26,19 +26,11 @@ using namespace Gtk;
ProgramChangeDialog::ProgramChangeDialog ()
: ArdourDialog (_("Add Program Change"), true)
, _channel (*manage (new Adjustment (1, 1, 16, 1, 2)))
, _program (*manage (new Adjustment (1, 1, 128, 1, 16)))
{
Table* t = manage (new Table (2, 2));
t->set_spacings (6);
Table* t = manage (new Table (1, 2));
Label* l = manage (new Label (_("Channel")));
l->set_alignment (0, 0.5);
t->attach (*l, 0, 1, 0, 1);
t->attach (_channel, 1, 2, 0, 1);
l = manage (new Label (_("Program")));
Label* l = manage (new Label (_("Program")));
l->set_alignment (0, 0.5);
t->attach (*l, 0, 1, 1, 2);
t->attach (_program, 1, 2, 1, 2);
@ -52,13 +44,6 @@ ProgramChangeDialog::ProgramChangeDialog ()
show_all ();
}
/** @return Channel, counted from 0 */
uint8_t
ProgramChangeDialog::channel () const
{
return _channel.get_value_as_int () - 1;
}
/** @return Program change number, counted from 0 */
uint8_t
ProgramChangeDialog::program () const

View File

@ -26,10 +26,8 @@ class ProgramChangeDialog : public ArdourDialog
public:
ProgramChangeDialog ();
uint8_t channel () const;
uint8_t program () const;
private:
Gtk::SpinButton _channel;
Gtk::SpinButton _program;
};