mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 23:35:03 +01:00
extend parts of StepSequencer API for better coding
This commit is contained in:
parent
ad29db76f3
commit
d37a61707b
2 changed files with 81 additions and 56 deletions
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <glibmm/threads.h>
|
||||
|
||||
#include "pbd/stateful.h"
|
||||
|
||||
#include "temporal/types.h"
|
||||
#include "temporal/beats.h"
|
||||
|
||||
|
|
@ -41,7 +43,7 @@ class TempoMap;
|
|||
typedef std::pair<Temporal::Beats,samplepos_t> BeatPosition;
|
||||
typedef std::vector<BeatPosition> BeatPositions;
|
||||
|
||||
class Step {
|
||||
class Step : public PBD::Stateful {
|
||||
public:
|
||||
enum Mode {
|
||||
AbsolutePitch,
|
||||
|
|
@ -55,6 +57,9 @@ class Step {
|
|||
void set_chord (size_t note_cnt, double* notes);
|
||||
void set_parameter (int number, double value, int n = 0);
|
||||
|
||||
void adjust_velocity (int amt);
|
||||
void adjust_pitch (int amt);
|
||||
|
||||
Mode mode() const { return _mode; }
|
||||
void set_mode (Mode m);
|
||||
|
||||
|
|
@ -84,6 +89,9 @@ class Step {
|
|||
|
||||
void set_timeline_offset (Temporal::Beats const &, Temporal::Beats const &);
|
||||
|
||||
XMLNode& get_state();
|
||||
int set_state (XMLNode const &, int);
|
||||
|
||||
private:
|
||||
friend class StepSequence; /* HACK */
|
||||
|
||||
|
|
@ -143,10 +151,11 @@ class StepSequence
|
|||
StepSequence (StepSequencer &myseq, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size);
|
||||
~StepSequence ();
|
||||
|
||||
void startup (Temporal::Beats const & start, Temporal::Beats const & offset);
|
||||
size_t nsteps() const { return _steps.size(); }
|
||||
|
||||
void adjust_step_pitch (int step, int amt);
|
||||
void adjust_step_velocity (int step, int amt);
|
||||
Step& step (size_t n) const;
|
||||
|
||||
void startup (Temporal::Beats const & start, Temporal::Beats const & offset);
|
||||
|
||||
Temporal::Beats bar_size() const { return _bar_size; }
|
||||
|
||||
|
|
@ -179,7 +188,7 @@ class StepSequence
|
|||
|
||||
private:
|
||||
StepSequencer& _sequencer;
|
||||
Glib::Threads::Mutex _step_lock;
|
||||
mutable Glib::Threads::Mutex _step_lock;
|
||||
typedef std::vector<Step*> Steps;
|
||||
|
||||
Steps _steps;
|
||||
|
|
@ -200,6 +209,11 @@ class StepSequencer {
|
|||
StepSequencer (TempoMap&, size_t nseqs, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size);
|
||||
~StepSequencer ();
|
||||
|
||||
size_t nsteps() const { return _sequences.front()->nsteps(); }
|
||||
size_t nsequences() const { return _sequences.size(); }
|
||||
|
||||
StepSequence& sequence (size_t n) const;
|
||||
|
||||
Temporal::Beats duration() const;
|
||||
|
||||
void startup (Temporal::Beats const & start, Temporal::Beats const & offset);
|
||||
|
|
@ -218,12 +232,8 @@ class StepSequencer {
|
|||
|
||||
TempoMap& tempo_map() const { return _tempo_map; }
|
||||
|
||||
/* editing */
|
||||
void adjust_step_pitch (int seq, int step, int amt);
|
||||
void adjust_step_velocity (int seq, int step, int amt);
|
||||
|
||||
private:
|
||||
Glib::Threads::Mutex _sequence_lock;
|
||||
mutable Glib::Threads::Mutex _sequence_lock;
|
||||
|
||||
typedef std::vector<StepSequence*> StepSequences;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include "pbd/i18n.h"
|
||||
|
||||
#include "ardour/audioengine.h"
|
||||
#include "ardour/midi_buffer.h"
|
||||
#include "ardour/midi_state_tracker.h"
|
||||
#include "ardour/step_sequencer.h"
|
||||
#include "ardour/tempo.h"
|
||||
|
||||
using namespace PBD;
|
||||
using namespace ARDOUR;
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -100,6 +103,44 @@ Step::set_enabled (bool yn)
|
|||
_enabled = yn;
|
||||
}
|
||||
|
||||
void
|
||||
Step::adjust_pitch (int amt)
|
||||
{
|
||||
Step::Note& note (_notes[0]);
|
||||
|
||||
note.number += amt;
|
||||
|
||||
if (note.number > 127.0) {
|
||||
note.number = 127.0;
|
||||
}
|
||||
|
||||
if (note.number < 0.0) {
|
||||
note.number = 0.0;
|
||||
}
|
||||
|
||||
PropertyChange pc;
|
||||
PropertyChanged (pc);
|
||||
}
|
||||
|
||||
void
|
||||
Step::adjust_velocity (int amt)
|
||||
{
|
||||
Step::Note& note (_notes[0]);
|
||||
|
||||
note.velocity += (1.0/128.0) * amt;
|
||||
|
||||
if (note.velocity > 127.0) {
|
||||
note.velocity = 127.0;
|
||||
}
|
||||
|
||||
if (note.velocity < 0.0) {
|
||||
note.velocity = 0.0;
|
||||
}
|
||||
|
||||
PropertyChange pc;
|
||||
PropertyChanged (pc);
|
||||
}
|
||||
|
||||
bool
|
||||
Step::run (MidiBuffer& buf, bool running, samplepos_t start_sample, samplepos_t end_sample, MidiStateTracker& tracker)
|
||||
{
|
||||
|
|
@ -266,6 +307,18 @@ Step::set_timeline_offset (Temporal::Beats const & start, Temporal::Beats const
|
|||
}
|
||||
}
|
||||
|
||||
XMLNode&
|
||||
Step::get_state ()
|
||||
{
|
||||
return *new XMLNode (X_("Step"));
|
||||
}
|
||||
|
||||
int
|
||||
Step::set_state (XMLNode const &, int)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
StepSequence::StepSequence (StepSequencer& s, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size)
|
||||
|
|
@ -334,44 +387,11 @@ StepSequence::run (MidiBuffer& buf, bool running, samplepos_t start_sample, samp
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
StepSequence::adjust_step_pitch (int step, int amt)
|
||||
Step&
|
||||
StepSequence::step (size_t n) const
|
||||
{
|
||||
if (step >= _steps.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Step::Note& note (_steps[step]->_notes[0]);
|
||||
|
||||
note.number += amt;
|
||||
|
||||
if (note.number > 127.0) {
|
||||
note.number = 127.0;
|
||||
}
|
||||
|
||||
if (note.number < 0.0) {
|
||||
note.number = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StepSequence::adjust_step_velocity (int step, int amt)
|
||||
{
|
||||
if (step >= _steps.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Step::Note& note (_steps[step]->_notes[0]);
|
||||
|
||||
note.velocity += (1.0/128.0) * amt;
|
||||
|
||||
if (note.velocity > 127.0) {
|
||||
note.velocity = 127.0;
|
||||
}
|
||||
|
||||
if (note.velocity < 0.0) {
|
||||
note.velocity = 0.0;
|
||||
}
|
||||
assert (n < _steps.size());
|
||||
return *_steps[n];
|
||||
}
|
||||
|
||||
/**/
|
||||
|
|
@ -440,14 +460,9 @@ StepSequencer::startup (Temporal::Beats const & start, Temporal::Beats const & o
|
|||
|
||||
}
|
||||
|
||||
void
|
||||
StepSequencer::adjust_step_pitch (int seq, int step, int amt)
|
||||
StepSequence&
|
||||
StepSequencer::sequence (size_t n) const
|
||||
{
|
||||
_sequences.front()->adjust_step_pitch (step, amt);
|
||||
}
|
||||
|
||||
void
|
||||
StepSequencer::adjust_step_velocity (int seq, int step, int amt)
|
||||
{
|
||||
_sequences.front()->adjust_step_velocity (step, amt);
|
||||
assert (n < _sequences.size());
|
||||
return *_sequences[n];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue