summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-02-16 02:51:16 +0000
committerDavid Robillard <d@drobilla.net>2009-02-16 02:51:16 +0000
commit3963d2b0b224e79fdf8e852e39fc3a765fa1431b (patch)
tree0c6c8a9d519d46437ffe9cb96f09ca337f33faff /libs/ardour/ardour
parentbeb3eea62bf217d0a7b2a86a96d5c375329df10a (diff)
Move all beats <-> frames time conversion into a single object that can be passed around.
This has 3 main benefits: - All conversion code is in one place (less duplication, potential bugs) - The conversion method can be passed to things that are ignorant of the actual time units involved, information required, etc. (In the future it would be nice to have user selectable tempo/frame time) - It should be relatively simple now to support tempo changes part-way through a MIDI region (at least architecturally speaking) git-svn-id: svn://localhost/ardour2/branches/3.0@4594 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r--libs/ardour/ardour/beats_frames_converter.h52
-rw-r--r--libs/ardour/ardour/midi_source.h21
-rw-r--r--libs/ardour/ardour/session.h6
3 files changed, 67 insertions, 12 deletions
diff --git a/libs/ardour/ardour/beats_frames_converter.h b/libs/ardour/ardour/beats_frames_converter.h
new file mode 100644
index 0000000000..79972cb4c5
--- /dev/null
+++ b/libs/ardour/ardour/beats_frames_converter.h
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2009 Paul Davis
+ Author: Dave Robillard
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+
+ $Id: midiregion.h 733 2006-08-01 17:19:38Z drobilla $
+*/
+
+#include <evoral/TimeConverter.hpp>
+#include <ardour/types.h>
+
+#ifndef __ardour_beats_frames_converter_h__
+#define __ardour_beats_frames_converter_h__
+
+namespace ARDOUR {
+
+class Session;
+
+class BeatsFramesConverter : public Evoral::TimeConverter<double,nframes_t> {
+public:
+ BeatsFramesConverter(Session& session, nframes_t origin)
+ : _session(session)
+ , _origin(origin)
+ {}
+
+ nframes_t to(double beats) const;
+ double from(nframes_t frames) const;
+
+ nframes_t origin() const { return _origin; }
+ void set_origin(nframes_t origin) { _origin = origin; }
+
+private:
+ Session& _session;
+ nframes_t _origin;
+};
+
+} /* namespace ARDOUR */
+
+#endif /* __ardour_beats_frames_converter_h__ */
diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h
index 3f8ed82310..3a28cde8c6 100644
--- a/libs/ardour/ardour/midi_source.h
+++ b/libs/ardour/ardour/midi_source.h
@@ -30,8 +30,7 @@
#include <ardour/ardour.h>
#include <ardour/buffer.h>
#include <ardour/source.h>
-
-using std::string;
+#include <ardour/beats_frames_converter.h>
namespace ARDOUR {
@@ -44,7 +43,7 @@ class MidiSource : public Source
public:
typedef double TimeType;
- MidiSource (Session& session, string name);
+ MidiSource (Session& session, std::string name);
MidiSource (Session& session, const XMLNode&);
virtual ~MidiSource ();
@@ -66,13 +65,13 @@ class MidiSource : public Source
virtual void mark_streaming_write_started ();
virtual void mark_streaming_write_completed ();
- uint64_t timeline_position () { return _timeline_position; }
- void set_timeline_position (nframes_t when) { _timeline_position = when; }
+ uint64_t timeline_position () { return _timeline_position; }
+ void set_timeline_position (nframes_t when);
virtual void session_saved();
- string captured_for() const { return _captured_for; }
- void set_captured_for (string str) { _captured_for = str; }
+ std::string captured_for() const { return _captured_for; }
+ void set_captured_for (std::string str) { _captured_for = str; }
uint32_t read_data_count() const { return _read_data_count; }
uint32_t write_data_count() const { return _write_data_count; }
@@ -96,6 +95,8 @@ class MidiSource : public Source
void set_model(boost::shared_ptr<MidiModel> m) { _model = m; }
void drop_model() { _model.reset(); }
+ BeatsFramesConverter& converter() { return _converter; }
+
protected:
virtual void flush_midi() = 0;
@@ -104,10 +105,12 @@ class MidiSource : public Source
virtual nframes_t write_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t cnt) = 0;
mutable Glib::Mutex _lock;
- string _captured_for;
+ std::string _captured_for;
uint64_t _timeline_position;
mutable uint32_t _read_data_count; ///< modified in read()
mutable uint32_t _write_data_count; ///< modified in write()
+
+ BeatsFramesConverter _converter;
boost::shared_ptr<MidiModel> _model;
bool _writing;
@@ -116,7 +119,7 @@ class MidiSource : public Source
mutable nframes_t _last_read_end;
private:
- bool file_changed (string path);
+ bool file_changed (std::string path);
};
}
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 8de0e1c523..ef25ebaea3 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -610,7 +610,7 @@ class Session : public PBD::StatefulDestructible
/* source management */
- struct import_status : public InterThreadInfo {
+ struct ImportStatus : public InterThreadInfo {
string doing_what;
/* control info */
@@ -624,8 +624,8 @@ class Session : public PBD::StatefulDestructible
SourceList sources;
};
- void import_audiofiles (import_status&);
- bool sample_rate_convert (import_status&, string infile, string& outfile);
+ void import_audiofiles (ImportStatus&);
+ bool sample_rate_convert (ImportStatus&, string infile, string& outfile);
string build_tmp_convert_name (string file);
boost::shared_ptr<ExportHandler> get_export_handler ();