Skip to content

Commit

Permalink
Issue #111 time-sig insertion solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahlstromcj committed Jul 5, 2023
1 parent 1c2e11a commit 3b68bc2
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 56 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# README for Seq66 0.99.7 2023-07-02
# README for Seq66 0.99.7 2023-07-04

__Seq66__: MIDI sequencer/live-looper with a hardware-sampler grid interface;
pattern banks, triggers, and playlists for song management; scale and chord
Expand Down Expand Up @@ -84,6 +84,8 @@ Windows, and using a conventional source tarball.
* Version 0.99.7:
* Issue #111 follow-ons: Fixed initial time-signature drawing in
data pane.
* Issue #110 follow-ons: Cannot save tempo (BPM) in Windows when
changed from main window.
* Version 0.99.6:
* Issue #3 follow-ons:
* Added a qscrollslave to allow QScrollArea to allow the pattern
Expand Down
3 changes: 2 additions & 1 deletion libseq66/include/midi/calculations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* \library seq66 application
* \author Chris Ahlstrom
* \date 2015-11-07
* \updates 2023-07-03
* \updates 2023-07-04
* \license GNU GPLv2 or above
*
* These items were moved from the globals.h module so that only the modules
Expand Down Expand Up @@ -211,6 +211,7 @@ extern midipulse midi_measures_to_pulses
const midi_measures & measures,
const midi_timing & seqparms
);
extern midi_measures string_to_measures (const std::string & bbt);
extern midipulse timestring_to_pulses
(
const std::string & timestring,
Expand Down
26 changes: 13 additions & 13 deletions libseq66/include/midi/editable_events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* \library seq66 application
* \author Chris Ahlstrom
* \date 2015-12-04
* \updates 2023-06-20
* \updates 2023-07-04
* \license GNU GPLv2 or above
*
* This module extends the event class to support conversions between events
Expand Down Expand Up @@ -106,7 +106,7 @@ class editable_events
* editable_events constructor by the caller.
*/

sequence & m_sequence;
sequence & m_seq;

/**
* Holds the current settings for the sequence (and usually for the whole
Expand Down Expand Up @@ -144,17 +144,7 @@ class editable_events
}

editable_event & lookup_link (const editable_event & ee);

/**
* Calculates the MIDI pulses (divisions) from a string using one of the
* free functions of the calculations module.
*/

midipulse string_to_pulses (const std::string & ts_string) const
{
return seq66::string_to_pulses(ts_string, timing());
}

midipulse string_to_pulses (const std::string & ts_string) const;
bool load_events ();
bool save_events ();

Expand Down Expand Up @@ -298,6 +288,16 @@ class editable_events

private:

const sequence & track () const
{
return m_seq;
}

sequence & track ()
{
return m_seq;
}

/**
* \setter m_current_event
*
Expand Down
14 changes: 8 additions & 6 deletions libseq66/include/play/sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* \library seq66 application
* \author Chris Ahlstrom
* \date 2015-07-30
* \updates 2023-07-03
* \updates 2023-07-05
* \license GNU GPLv2 or above
*
* The functions add_list_var() and add_long_list() have been replaced by
Expand Down Expand Up @@ -287,10 +287,11 @@ class sequence
{
double sig_start_measure; /* Starting measure, precalculated. */
double sig_measures; /* Size in measures, precalculated. */
midipulse sig_start_tick; /* The pulse where time-sig was placed. */
midipulse sig_end_tick; /* Next time-sig start (0 == end?). */
int sig_beats_per_bar; /* The beats-per-bar in the time-sig. */
int sig_beat_width; /* The size of each beat in the bar. */
int sig_ticks_per_beat; /* Simplifies later calculations. */
midipulse sig_start_tick; /* The pulse where time-sig was placed. */
midipulse sig_end_tick; /* Next time-sig start (0 == end?). */
};

/**
Expand Down Expand Up @@ -1056,9 +1057,10 @@ class sequence
return int(m_time_signatures.size());
}

const timesig & get_time_signature (size_t index);
bool current_time_signature (midipulse p, int & beats, int & beatwidth);
int measure_number (midipulse p);
const timesig & get_time_signature (size_t index) const;
bool current_time_signature (midipulse p, int & beats, int & beatwidth) const;
int measure_number (midipulse p) const;
midipulse time_signature_pulses (const std::string & s) const;

bool is_recorder_seq () const
{
Expand Down
36 changes: 35 additions & 1 deletion libseq66/src/midi/calculations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* \library seq66 application
* \author Chris Ahlstrom
* \date 2015-11-07
* \updates 2023-06-21
* \updates 2023-07-04
* \license GNU GPLv2 or above
*
* This code was moved from the globals module so that other modules
Expand Down Expand Up @@ -646,6 +646,40 @@ midi_measures_to_pulses
return result;
}

/**
* A new function to create a midi_measures structure from a string assumed
* to have a formate of "B:B:T". Any fractional part is ignored as being
* less than a pulse.
*/

midi_measures
string_to_measures (const std::string & bbt)
{
std::string m;
std::string b;
std::string t;
std::string fraction;
int count = extract_timing_numbers(bbt, m, b, t, fraction);
if (count > 0)
{
int measures = strtoi(m);
int beats = strtoi(b);
int ticks = strtoi(t);
if (measures == 0)
measures = 1;

if (beats == 0)
beats = 1;

return midi_measures(measures, beats, ticks);
}
else
{
static midi_measures s_dummy;
return s_dummy;
}
}

/**
* Converts a string that represents "hours:minutes:seconds.fraction" into a
* MIDI pulse/ticks/clock value.
Expand Down
39 changes: 27 additions & 12 deletions libseq66/src/midi/editable_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* \library seq66 application
* \author Chris Ahlstrom
* \date 2015-12-04
* \updates 2021-08-19
* \updates 2023-07-04
* \license GNU GPLv2 or above
*
* A MIDI editable event is encapsulated by the seq66::editable_events
Expand Down Expand Up @@ -60,13 +60,13 @@ namespace seq66
* get and provides in this parameter.
*/

editable_events::editable_events (sequence & seq, midibpm bpm) :
editable_events::editable_events (sequence & s, midibpm bp) :
m_events (),
m_current_event (m_events.end()),
m_sequence (seq),
m_seq (s),
m_midi_parameters
(
bpm, seq.get_beats_per_bar(), seq.get_beat_width(), seq.get_ppqn()
bp, s.get_beats_per_bar(), s.get_beat_width(), s.get_ppqn()
)
{
// Empty body
Expand All @@ -87,7 +87,7 @@ editable_events::editable_events (sequence & seq, midibpm bpm) :
editable_events::editable_events (const editable_events & rhs) :
m_events (rhs.m_events),
m_current_event (rhs.m_current_event),
m_sequence (rhs.m_sequence),
m_seq (rhs.m_seq),
m_midi_parameters (rhs.m_midi_parameters)
{
// no code
Expand All @@ -113,7 +113,7 @@ editable_events::operator = (const editable_events & rhs)
m_events = rhs.m_events;
m_current_event = rhs.m_current_event;
m_midi_parameters = rhs.m_midi_parameters;
m_sequence.partial_assign(rhs.m_sequence);
m_seq.partial_assign(rhs.m_seq);
}
return *this;
}
Expand Down Expand Up @@ -212,8 +212,8 @@ bool
editable_events::load_events ()
{
bool result;
int original_count = m_sequence.events().count();
for (const auto & ei : m_sequence.events())
int original_count = track().events().count();
for (const auto & ei : track().events())
{
if (! add(ei))
break;
Expand Down Expand Up @@ -244,27 +244,42 @@ editable_events::save_events ()
bool result = count() > 0;
if (result)
{
m_sequence.events().clear();
track().events().clear();
for (const auto & ei : events())
{
if (! m_sequence.add_event(ei.second)) /* sorts the events */
if (! track().add_event(ei.second)) /* sorts the events */
break;
}
result = m_sequence.events().count () == count();
result = track().events().count () == count();
if (result)
{
/*
* ca 2021-0-02 Reload in case of note changes.
*/

m_sequence.events().verify_and_link();
track().events().verify_and_link();
clear();
result = load_events();
}
}
return result;
}

/**
* Calculates the MIDI pulses (divisions) from a string using one of the
* free functions of the calculations module.
*/

midipulse
editable_events::string_to_pulses (const std::string & ts_string) const
{
#if defined USE_OLD_CODE
return seq66::string_to_pulses(ts_string, timing());
#else
return track().time_signature_pulses(ts_string);
#endif
}

/**
* Gets the index (integer position in the map) of the linked event, if any.
*/
Expand Down
15 changes: 9 additions & 6 deletions libseq66/src/play/performer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* \library seq66 application
* \author Chris Ahlstrom and others
* \date 2018-11-12
* \updates 2023-06-29
* \updates 2023-07-03
* \license GNU GPLv2 or above
*
* Also read the comments in the Seq64 version of this module, perform.
Expand Down Expand Up @@ -2193,6 +2193,12 @@ performer::fix_sequence (seq::number seqno, fixparameters & params)
* Note that we do not set the modify flag or do notification notification
* here. See the change_ppqn() function instead.
*
* Setting the "R" marker to 4 times a measure seems wrong, and makes the R
* in the seqedit unseen. But it works for the perfedit. We could loop
* through all patterns to find the shortest one, but it's simpler to
* just set the "R" to 1 measure. Perhaps multiply it by 4 if the song editor
* is opened.
*
* \setter ppqn
* Also sets other related members.
*
Expand Down Expand Up @@ -2225,14 +2231,11 @@ performer::set_ppqn (int p)
}
if (m_one_measure == 0)
{
m_one_measure = p * 4; /* simplistic! */
m_right_tick = m_one_measure = p * 4; /* simplistic! */

/*
* ca 2022-08-17 This seems wrong, and makes the R in
* the seqedit unseen. But it works for the perfedit.
* m_right_tick = m_one_measure * 4;
*/

m_right_tick = m_one_measure * 4;
}
return result;
}
Expand Down
Loading

0 comments on commit 3b68bc2

Please sign in to comment.