More solid "fake" recording and serialization
authorDavid Robillard <d@drobilla.net>
Mon, 14 Aug 2006 23:29:01 +0000 (23:29 +0000)
committerDavid Robillard <d@drobilla.net>
Mon, 14 Aug 2006 23:29:01 +0000 (23:29 +0000)
git-svn-id: svn://localhost/ardour2/branches/midi@825 d708f5d6-7413-0410-9779-e7cbd77b26cf

16 files changed:
gtk2_ardour/editor_tempodisplay.cc
gtk2_ardour/midi_streamview.cc
libs/ardour/ardour/diskstream.h
libs/ardour/ardour/midi_diskstream.h
libs/ardour/ardour/midi_playlist.h
libs/ardour/ardour/midi_region.h
libs/ardour/ardour/midi_source.h
libs/ardour/ardour/smf_source.h
libs/ardour/midi_diskstream.cc
libs/ardour/midi_playlist.cc
libs/ardour/midi_region.cc
libs/ardour/midi_source.cc
libs/ardour/session.cc
libs/ardour/smf_source.cc
libs/ardour/source.cc
libs/ardour/utils.cc

index 2e4e092ebd4e01a76dcbc962e7f6286b8189a8d1..ff99c76351d0fd71177e08a6c6f5301670c1e6a6 100644 (file)
@@ -216,7 +216,7 @@ Editor::draw_measures ()
                                   are large.
                                */
 
-                               if (beat_spacing < 25.0) {
+                               if (beat_spacing < 15.0) {
                                        break;
                                }
                        }
index 5f939ab58306a5a3c15db4521c9ffe5f52790cab..9e72a16816c770d40466c6987ed7e72987baa9a7 100644 (file)
@@ -153,8 +153,6 @@ MidiStreamView::setup_rec_box ()
 
        if (_trackview.session().transport_rolling()) {
 
-               cerr << "\tSHOW: rolling\n";
-
                if (!rec_active && 
                    _trackview.session().record_status() == Session::Recording && 
                    _trackview.get_diskstream()->record_enabled()) {
@@ -165,13 +163,11 @@ MidiStreamView::setup_rec_box ()
 
                                MidiRegion::SourceList sources;
 
-                               // FIXME
                                MidiDiskstream* mds = dynamic_cast<MidiDiskstream*>(_trackview.get_diskstream());
                                assert(mds);
 
                                sources.push_back((Source*)mds->write_source());
                                
-                               // FIXME
                                rec_data_ready_connections.push_back (mds->write_source()->ViewDataRangeReady.connect (bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), mds->write_source()))); 
 
                                // handle multi
@@ -224,16 +220,10 @@ MidiStreamView::setup_rec_box ()
                        rec_updating = true;
                        rec_active = true;
 
-                       // Show, damn you!
-                       rec_rect->show();
-                       rec_rect->raise_to_top();
-
                } else if (rec_active &&
                           (_trackview.session().record_status() != Session::Recording ||
                            !_trackview.get_diskstream()->record_enabled())) {
 
-                       cerr << "NO SHOW 1\n";
-
                        screen_update_connection.disconnect();
                        rec_active = false;
                        rec_updating = false;
@@ -310,7 +300,7 @@ MidiStreamView::update_rec_regions ()
                                continue;
                        }
                        
-                       // FIXME
+                       // FIXME?
                        MidiRegion * region = dynamic_cast<MidiRegion*>(*iter);
                        assert(region);
 
index fa1126901d8c6d74b2a357f6f9223cd327147199..080343691390fe954f727b459d232245b2feef4d 100644 (file)
@@ -124,7 +124,6 @@ class Diskstream : public Stateful, public sigc::trackable
        virtual XMLNode& get_state(void) = 0;
        virtual int      set_state(const XMLNode& node) = 0;
        
-       // FIXME: makes sense for all diskstream types?
        virtual void monitor_input (bool) {}
 
        jack_nframes_t capture_offset() const { return _capture_offset; }
index 8085e6509aaff29ffd2078369fbdf3a8d8b43aaf..901baf3c640cb4605f00f6bbbaef5aeb0568c619 100644 (file)
@@ -124,7 +124,7 @@ class MidiDiskstream : public Diskstream
        
        int do_refill_with_alloc();
 
-       int read (RawMidi* buf, jack_nframes_t& start, jack_nframes_t cnt, bool reversed);
+       int read (MidiBuffer& dst, jack_nframes_t& start, jack_nframes_t cnt, bool reversed);
 
        void finish_capture (bool rec_monitors_input);
        void transport_stopped (struct tm&, time_t, bool abort);
index 51cb00822e47a553f9d66ed20b68c5c9909a520d..9e9cf250e2802f3fea885079e54c143078cdf715 100644 (file)
@@ -33,6 +33,7 @@ class Session;
 class Region;
 class MidiRegion;
 class Source;
+class MidiBuffer;
 
 class MidiPlaylist : public ARDOUR::Playlist
 {
@@ -55,7 +56,7 @@ public:
        MidiPlaylist (const MidiPlaylist&, jack_nframes_t start, jack_nframes_t cnt,
                      string name, bool hidden = false);
 
-       jack_nframes_t read (RawMidi *dst, RawMidi *mixdown,
+       jack_nframes_t read (MidiBuffer& buf,
                             jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0);
 
        int set_state (const XMLNode&);
index f68c0ba3cafca52f70cc879c233671862b3fecbe..0144f5247351ac067bc0e3cca99d1f7509d9869f 100644 (file)
@@ -41,6 +41,7 @@ class Playlist;
 class Session;
 class MidiFilter;
 class MidiSource;
+class MidiBuffer;
 
 class MidiRegion : public Region
 {
@@ -56,14 +57,14 @@ class MidiRegion : public Region
 
        MidiSource& midi_source (uint32_t n=0) const;
 
-       jack_nframes_t read_at (RawMidi* out, RawMidi* mix,
+       jack_nframes_t read_at (MidiBuffer& out,
                        jack_nframes_t position,
                        jack_nframes_t cnt, 
                        uint32_t       chan_n      = 0,
                        jack_nframes_t read_frames = 0,
                        jack_nframes_t skip_frames = 0) const;
 
-       jack_nframes_t master_read_at (RawMidi* buf, RawMidi* mix,
+       jack_nframes_t master_read_at (MidiBuffer& buf,
                        jack_nframes_t position,
                        jack_nframes_t cnt,
                        uint32_t chan_n=0) const;
@@ -82,7 +83,7 @@ class MidiRegion : public Region
        StateManager::State* state_factory (std::string why) const;
        Change restore_state (StateManager::State&);
 
-       jack_nframes_t _read_at (const SourceList&, RawMidi *buf,
+       jack_nframes_t _read_at (const SourceList&, MidiBuffer& buf,
                jack_nframes_t position,
                jack_nframes_t cnt, 
                uint32_t chan_n = 0,
index d4fec52609e0cd9e9832fc553d80afc89cf4788f..2ecae5c37bb9e77a13e3ff381298f33513651f89 100644 (file)
@@ -37,7 +37,9 @@ using std::string;
 
 namespace ARDOUR {
 
-/** Source for raw MIDI data */
+class MidiBuffer;
+
+/** Source for MIDI data */
 class MidiSource : public Source
 {
   public:
@@ -45,8 +47,8 @@ class MidiSource : public Source
        MidiSource (const XMLNode&);
        virtual ~MidiSource ();
 
-       virtual jack_nframes_t read (RawMidi *dst, jack_nframes_t start, jack_nframes_t cnt) const;
-       virtual jack_nframes_t write (RawMidi *src, jack_nframes_t cnt);
+       virtual jack_nframes_t read (MidiBuffer& dst, jack_nframes_t start, jack_nframes_t cnt) const;
+       virtual jack_nframes_t write (MidiBuffer& src, jack_nframes_t cnt);
 
        virtual void mark_for_remove() = 0;
        virtual void mark_streaming_write_completed () {}
@@ -68,8 +70,8 @@ class MidiSource : public Source
        int set_state (const XMLNode&);
 
   protected:
-       virtual jack_nframes_t read_unlocked (RawMidi* dst, jack_nframes_t start, jack_nframes_t cn) const = 0;
-       virtual jack_nframes_t write_unlocked (RawMidi* dst, jack_nframes_t cnt) = 0;
+       virtual jack_nframes_t read_unlocked (MidiBuffer& dst, jack_nframes_t start, jack_nframes_t cnt) const = 0;
+       virtual jack_nframes_t write_unlocked (MidiBuffer& dst, jack_nframes_t cnt) = 0;
        
        mutable Glib::Mutex _lock;
        string              _captured_for;
index abb52456e3381bcafd6f8cc655265bc200c37c7f..d5bcd3ee4c40b85a5a2654d54513e02b9754a25d 100644 (file)
@@ -27,6 +27,8 @@
 
 namespace ARDOUR {
 
+class MidiBuffer;
+
 /** Standard Midi File (Type 0) Source */
 class SMFSource : public MidiSource {
   public:
@@ -86,8 +88,8 @@ class SMFSource : public MidiSource {
 
        int init (string idstr, bool must_exist);
 
-       jack_nframes_t read_unlocked (RawMidi* dst, jack_nframes_t start, jack_nframes_t cn) const;
-       jack_nframes_t write_unlocked (RawMidi* dst, jack_nframes_t cnt);
+       jack_nframes_t read_unlocked (MidiBuffer& dst, jack_nframes_t start, jack_nframes_t cn) const;
+       jack_nframes_t write_unlocked (MidiBuffer& dst, jack_nframes_t cnt);
 
        bool find (std::string path, bool must_exist, bool& is_new);
        bool removable() const;
index 2c88d5daa8d0d2a2d3462299008dcf79b1d6b3ac..86a95a3cc0ccc1fb60f54c820d0b833d9819d110 100644 (file)
@@ -544,12 +544,14 @@ MidiDiskstream::process (jack_nframes_t transport_frame, jack_nframes_t nframes,
                        // FIXME: reading from a MIDI port is different, can't just memcpy
                        //memcpy (_current_capture_buffer, _io->input(0)->get_buffer (rec_nframes) + offset + rec_offset, sizeof (RawMidi) * rec_nframes);
                        assert(_source_port);
-                       for (size_t i=0; i < _source_port->size(); ++i) {
-                               cerr << "DISKSTREAM GOT EVENT " << i << "!!\n";
+                       
+                       /*for (size_t i=0; i < _source_port->size(); ++i) {
+                               cerr << "DISKSTREAM GOT EVENT(1) " << i << "!!\n";
                        }
 
-                       //if (_source_port->size() == 0)
-                       //      cerr << "No events :/ (1)\n";
+                       if (_source_port->size() == 0)
+                               cerr << "No events :/ (1)\n";
+                       */
 
 
                } else {
@@ -565,11 +567,15 @@ MidiDiskstream::process (jack_nframes_t transport_frame, jack_nframes_t nframes,
                        // FIXME (see above)
                        //RawMidi* buf = _io->input (0)->get_buffer (nframes) + offset;
                        assert(_source_port);
+
+                       /*
                        for (size_t i=0; i < _source_port->size(); ++i) {
-                               cerr << "DISKSTREAM GOT EVENT " << i << "!!\n";
+                               cerr << "DISKSTREAM GOT EVENT(2) " << i << "!!\n";
                        }
-                       //if (_source_port->size() == 0)
-                       //      cerr << "No events :/ (2)\n";
+                       if (_source_port->size() == 0)
+                               cerr << "No events :/ (2)\n";
+                       */
+
                        RawMidi* buf = NULL; // FIXME FIXME FIXME (make it compile)
                        assert(false);
                        jack_nframes_t first = _capture_vector.len[0];
@@ -592,8 +598,8 @@ MidiDiskstream::process (jack_nframes_t transport_frame, jack_nframes_t nframes,
        if (rec_nframes) {
                
                // FIXME: filthy hack to fool the GUI into thinking we're doing something
-               if (_write_source)
-                       _write_source->ViewDataRangeReady (transport_frame, rec_nframes); /* EMIT SIGNAL */
+               //if (_write_source)
+               //      _write_source->ViewDataRangeReady (transport_frame, rec_nframes); /* EMIT SIGNAL */
 
                /* data will be written to disk */
 
@@ -802,7 +808,7 @@ MidiDiskstream::internal_playback_seek (jack_nframes_t distance)
 }
 
 int
-MidiDiskstream::read (RawMidi* buf, jack_nframes_t& start, jack_nframes_t cnt, bool reversed)
+MidiDiskstream::read (MidiBuffer& dst, jack_nframes_t& start, jack_nframes_t cnt, bool reversed)
 {
        return 0;
 }
index 443c5b57bf49681f1643fd7545b93a67f01e404b..582df6f5bebb6d0a78e6080c8b278922e137bf1d 100644 (file)
@@ -170,7 +170,7 @@ struct RegionSortByLayer
 
 /** FIXME: semantics of return value? */
 jack_nframes_t
-MidiPlaylist::read (RawMidi *buf, RawMidi *mixdown_buffer, jack_nframes_t start,
+MidiPlaylist::read (MidiBuffer& buf, jack_nframes_t start,
                      jack_nframes_t cnt, unsigned chan_n)
 {
        /* this function is never called from a realtime thread, so
@@ -199,7 +199,7 @@ MidiPlaylist::read (RawMidi *buf, RawMidi *mixdown_buffer, jack_nframes_t start,
        sort(regs.begin(), regs.end(), layer_cmp);
 
        for (vector<MidiRegion*>::iterator i = regs.begin(); i != regs.end(); ++i) {
-                       (*i)->read_at (buf, mixdown_buffer, start, cnt, chan_n, read_frames, skip_frames);
+                       (*i)->read_at (buf, start, cnt, chan_n, read_frames, skip_frames);
                        ret += (*i)->read_data_count();
        }
 
index 5b8a49049ea80ef581b9db6ca5d38323c555c240..84b03b9aa9b8270bcfd397ccebcb5ec1a1f8c22e 100644 (file)
@@ -55,6 +55,8 @@ MidiRegion::MidiRegion (MidiSource& src, jack_nframes_t start, jack_nframes_t le
        if (announce) {
                 CheckNewRegion (this); /* EMIT SIGNAL */
        }
+       
+       assert(_name.find("/") == string::npos);
 }
 
 /* Basic MidiRegion constructor (one channel) */
@@ -66,6 +68,8 @@ MidiRegion::MidiRegion (MidiSource& src, jack_nframes_t start, jack_nframes_t le
        if (announce) {
                 CheckNewRegion (this); /* EMIT SIGNAL */
        }
+
+       assert(_name.find("/") == string::npos);
 }
 
 /* Basic MidiRegion constructor (many channels) */
@@ -77,6 +81,8 @@ MidiRegion::MidiRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t l
        if (announce) {
                 CheckNewRegion (this); /* EMIT SIGNAL */
        }
+       
+       assert(_name.find("/") == string::npos);
 }
 
 
@@ -89,6 +95,8 @@ MidiRegion::MidiRegion (const MidiRegion& other, jack_nframes_t offset, jack_nfr
        if (announce) {
                CheckNewRegion (this); /* EMIT SIGNAL */
        }
+       
+       assert(_name.find("/") == string::npos);
 }
 
 MidiRegion::MidiRegion (const MidiRegion &other)
@@ -97,6 +105,7 @@ MidiRegion::MidiRegion (const MidiRegion &other)
        save_state ("initial state");
 
        /* NOTE: no CheckNewRegion signal emitted here. This is the copy constructor */
+       assert(_name.find("/") == string::npos);
 }
 
 MidiRegion::MidiRegion (MidiSource& src, const XMLNode& node)
@@ -108,6 +117,7 @@ MidiRegion::MidiRegion (MidiSource& src, const XMLNode& node)
 
        save_state ("initial state");
 
+       assert(_name.find("/") == string::npos);
        assert(_type == DataType::MIDI);
 
        CheckNewRegion (this); /* EMIT SIGNAL */
@@ -122,6 +132,7 @@ MidiRegion::MidiRegion (SourceList& srcs, const XMLNode& node)
 
        save_state ("initial state");
 
+       assert(_name.find("/") == string::npos);
        assert(_type == DataType::MIDI);
 
        CheckNewRegion (this); /* EMIT SIGNAL */
@@ -167,7 +178,7 @@ MidiRegion::get_memento() const
 }
 
 jack_nframes_t
-MidiRegion::read_at (RawMidi *out, RawMidi* mix_buf, jack_nframes_t position, 
+MidiRegion::read_at (MidiBuffer& out, jack_nframes_t position, 
                      jack_nframes_t cnt, 
                      uint32_t chan_n, jack_nframes_t read_frames, jack_nframes_t skip_frames) const
 {
@@ -175,14 +186,14 @@ MidiRegion::read_at (RawMidi *out, RawMidi* mix_buf, jack_nframes_t position,
 }
 
 jack_nframes_t
-MidiRegion::master_read_at (RawMidi *out, RawMidi* mix_buf, jack_nframes_t position, 
+MidiRegion::master_read_at (MidiBuffer& out, jack_nframes_t position, 
                             jack_nframes_t cnt, uint32_t chan_n) const
 {
        return _read_at (_master_sources, out, position, cnt, chan_n, 0, 0);
 }
 
 jack_nframes_t
-MidiRegion::_read_at (const SourceList& srcs, RawMidi *buf, 
+MidiRegion::_read_at (const SourceList& srcs, MidiBuffer& buf, 
                       jack_nframes_t position, jack_nframes_t cnt, 
                       uint32_t chan_n, jack_nframes_t read_frames, jack_nframes_t skip_frames) const
 {
index 6728231de676f88f1e3141aa86d9594ef9a4612e..802324e19bac620ff6ad53cc0baeb0df7adbf237 100644 (file)
@@ -90,14 +90,14 @@ MidiSource::set_state (const XMLNode& node)
 }
 
 jack_nframes_t
-MidiSource::read (RawMidi* dst, jack_nframes_t start, jack_nframes_t cnt) const
+MidiSource::read (MidiBuffer& dst, jack_nframes_t start, jack_nframes_t cnt) const
 {
        Glib::Mutex::Lock lm (_lock);
        return read_unlocked (dst, start, cnt);
 }
 
 jack_nframes_t
-MidiSource::write (RawMidi* dst, jack_nframes_t cnt)
+MidiSource::write (MidiBuffer& dst, jack_nframes_t cnt)
 {
        Glib::Mutex::Lock lm (_lock);
        return write_unlocked (dst, cnt);
index 33165574a80e3167090ff91f5d183ce7dfd880d6..ab8d8674142d5d00086bde3182f408c6d7e0145b 100644 (file)
@@ -2480,7 +2480,7 @@ Session::diskstream_by_id (const PBD::ID& id)
        return 0;
 }
 
-/* AudioRegion management */
+/* Region management */
 
 string
 Session::new_region_name (string old)
@@ -2539,6 +2539,8 @@ Session::region_name (string& result, string base, bool newlevel) const
        char buf[16];
        string subbase;
 
+       assert(base.find("/") == string::npos);
+
        if (base == "") {
                
                Glib::Mutex::Lock lm (region_lock);
index 9a03d0fabd38b6fc94e05b7dbe20405eccb8c50d..dfe1419c4e6df6ec5d9aa86b458111a6f15a6d73 100644 (file)
@@ -47,7 +47,7 @@ uint64_t                              SMFSource::header_position_offset;
 */
 
 SMFSource::SMFSource (std::string path, Flag flags)
-       : MidiSource (path), _flags (flags)
+       : MidiSource (region_name_from_path(path)), _flags (flags)
 {
        /* constructor used for new internal-to-session files. file cannot exist */
 
@@ -55,6 +55,8 @@ SMFSource::SMFSource (std::string path, Flag flags)
                throw failed_constructor ();
        }
        
+       assert(_name.find("/") == string::npos);
+
        SourceCreated (this); /* EMIT SIGNAL */
 }
 
@@ -71,6 +73,8 @@ SMFSource::SMFSource (const XMLNode& node)
                throw failed_constructor ();
        }
        
+       assert(_name.find("/") == string::npos);
+       
        SourceCreated (this); /* EMIT SIGNAL */
 }
 
@@ -91,10 +95,8 @@ SMFSource::removable () const
 int
 SMFSource::init (string pathstr, bool must_exist)
 {
-       bool is_new = false;
+       //bool is_new = false;
 
-       _length = 1024; // FIXME FIXME FIXME: force save
-       
        /*
        if (!find (pathstr, must_exist, is_new)) {
                cerr << "cannot find " << pathstr << " with me = " << must_exist << endl;
@@ -106,8 +108,9 @@ SMFSource::init (string pathstr, bool must_exist)
        }
        */
 
-       // Yeah, we sound it.  Swear.
+       // Yeah, we found it.  Swear.
 
+       assert(_name.find("/") == string::npos);
        return 0;
 }
 
@@ -124,15 +127,18 @@ SMFSource::flush_header ()
 }
 
 jack_nframes_t
-SMFSource::read_unlocked (RawMidi* dst, jack_nframes_t start, jack_nframes_t cnt) const
+SMFSource::read_unlocked (MidiBuffer& dst, jack_nframes_t start, jack_nframes_t cnt) const
 {
-       return 0;
+       dst.clear();
+       return cnt;
 }
 
 jack_nframes_t
-SMFSource::write_unlocked (RawMidi* dst, jack_nframes_t cnt)
+SMFSource::write_unlocked (MidiBuffer& src, jack_nframes_t cnt)
 {
-       return 0;
+       ViewDataRangeReady (_length, cnt); /* EMIT SIGNAL */
+       _length += cnt;
+       return cnt;
 }
 
 XMLNode&
@@ -166,6 +172,8 @@ SMFSource::set_state (const XMLNode& node)
 
        }
 
+       assert(_name.find("/") == string::npos);
+
        return 0;
 }
 
index 1506983e1811419c779ec623a5556c66dcb42c46..bf07ede70b725a1d13412c9389cd62592455c6cb 100644 (file)
@@ -48,6 +48,8 @@ sigc::signal<void,Source*> Source::SourceCreated;
 Source::Source (string name, DataType type)
        : _type(type)
 {
+       assert(_name.find("/") == string::npos);
+
        _name = name;
        _use_cnt = 0;
        _timestamp = 0;
@@ -62,6 +64,7 @@ Source::Source (const XMLNode& node)
        if (set_state (node) || _type == DataType::NIL) {
                throw failed_constructor();
        }
+       assert(_name.find("/") == string::npos);
 }
 
 Source::~Source ()
@@ -111,6 +114,7 @@ Source::set_state (const XMLNode& node)
        if ((prop = node.property ("timestamp")) != 0) {
                sscanf (prop->value().c_str(), "%ld", &_timestamp);
        }
+       assert(_name.find("/") == string::npos);
 
        return 0;
 }
index 78e5572a3ddb20aa994a3fe6de687d488f9ab672..26b5966086f8cf58c33e9de0aeee188cd95c2e6a 100644 (file)
@@ -203,6 +203,12 @@ region_name_from_path (string path)
 {
        string::size_type pos;
 
+       /* remove any leading path */
+
+       if ((pos = path.find_last_of ('/')) != string::npos) {
+               path = path.substr(pos+1);
+       }
+
        /* remove filename suffixes etc. */
        
        if ((pos = path.find_last_of ('.')) != string::npos) {