Clean up.
authorDavid Robillard <d@drobilla.net>
Sun, 15 Feb 2009 01:53:06 +0000 (01:53 +0000)
committerDavid Robillard <d@drobilla.net>
Sun, 15 Feb 2009 01:53:06 +0000 (01:53 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@4572 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/smf_source.h
libs/ardour/audio_diskstream.cc
libs/ardour/midi_diskstream.cc
libs/ardour/smf_source.cc

index 1dd993c686522cfb10cbda6e9b8b8358e6fe3159..82f41ebf2d74a906d9de7f9d22f77a88a7c13cd6 100644 (file)
@@ -54,16 +54,6 @@ class SMFSource : public MidiSource, public Evoral::SMF {
 
        virtual ~SMFSource ();
 
-       /* this block of methods do nothing for regular file sources, but are significant
-          for files used in destructive recording.
-       */
-       // FIXME and thus are useless for MIDI.. but make MidiDiskstream compile easier! :)
-
-       virtual nframes_t last_capture_start_frame() const { return 0; }
-       virtual void      mark_capture_start (nframes_t) {}
-       virtual void      mark_capture_end () {}
-       virtual void      clear_capture_marks() {}
-
        bool set_name (const std::string& newname) { return (set_source_name(newname, false) == 0); }
        int set_source_name (string newname, bool destructive);
        
@@ -98,7 +88,6 @@ class SMFSource : public MidiSource, public Evoral::SMF {
        void flush_midi();
 
   private:
-
        int init (string idstr, bool must_exist);
 
        nframes_t read_unlocked (
index 2982b0f2f8b742e69896c3eff731cf683af76287..78f5ee29e2e8a490c82eb304741bf8d5c6178683 100644 (file)
@@ -1642,9 +1642,10 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca
                */
                
                try {
-                       boost::shared_ptr<Region> rx (RegionFactory::create (srcs, c->front()->write_source->last_capture_start_frame(), total_capture, 
-                                                                            whole_file_region_name,
-                                                                            0, AudioRegion::Flag (AudioRegion::DefaultFlags|AudioRegion::Automatic|AudioRegion::WholeFile)));
+                       boost::shared_ptr<Region> rx (RegionFactory::create (srcs,
+                                               c->front()->write_source->last_capture_start_frame(), total_capture, 
+                                               whole_file_region_name, 0,
+                                               Region::Flag (Region::DefaultFlags|Region::Automatic|Region::WholeFile)));
 
                        region = boost::dynamic_pointer_cast<AudioRegion> (rx);
                        region->special_set_position (capture_info.front()->start);
index 41f8eb9e196b493b828955892a78a2a8465469d0..f960c170db095fbdbf1c1284ced71b7846613b2c 100644 (file)
@@ -990,9 +990,9 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap
                   */
 
                try {
-                       boost::shared_ptr<Region> rx (RegionFactory::create (srcs, _write_source->last_capture_start_frame(), total_capture, 
-                                                                            whole_file_region_name, 
-                                                                            0, Region::Flag (Region::DefaultFlags|Region::Automatic|Region::WholeFile)));
+                       boost::shared_ptr<Region> rx (RegionFactory::create (srcs, 0,
+                                       total_capture, whole_file_region_name, 0,
+                                       Region::Flag (Region::DefaultFlags|Region::Automatic|Region::WholeFile)));
 
                        region = boost::dynamic_pointer_cast<MidiRegion> (rx);
                        region->special_set_position (capture_info.front()->start);
@@ -1011,7 +1011,7 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap
                XMLNode &before = _playlist->get_state();
                _playlist->freeze ();
 
-               for (buffer_position = _write_source->last_capture_start_frame(), ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
+               for (buffer_position = 0, ci = capture_info.begin(); ci != capture_info.end(); ++ci) {
 
                        string region_name;
 
index d75c4b93d55ae57bac461b142c653186bc3a06b5..babcb0ca47a62c98266b5917876ceae5cce25ead 100644 (file)
@@ -48,16 +48,16 @@ using namespace ARDOUR;
 
 string SMFSource::_search_path;
 
-SMFSource::SMFSource (Session& s, std::string path, Flag flags)
-       : MidiSource (s, region_name_from_path(path, false))
-       , Evoral::SMF ()
-       , _flags (Flag(flags | Writable)) // FIXME: this needs to be writable for now
+SMFSource::SMFSource(Session& s, std::string path, Flag flags)
+       : MidiSource(s, region_name_from_path(path, false))
+       , Evoral::SMF()
+       , _flags(flags)
        , _allow_remove_if_empty(true)
        , _last_ev_time(0)
 {
-       /* constructor used for new internal-to-session files. file cannot exist */
+       /* Constructor used for new internal-to-session files.  File cannot exist. */
 
-       if (init (path, false)) {
+       if (init(path, false)) {
                throw failed_constructor ();
        }
        
@@ -68,19 +68,19 @@ SMFSource::SMFSource (Session& s, std::string path, Flag flags)
        assert(_name.find("/") == string::npos);
 }
 
-SMFSource::SMFSource (Session& s, const XMLNode& node)
-       : MidiSource (s, node)
-       , _flags (Flag (Writable|CanRename))
+SMFSource::SMFSource(Session& s, const XMLNode& node)
+       : MidiSource(s, node)
+       , _flags(Flag(Writable|CanRename))
        , _allow_remove_if_empty(true)
        , _last_ev_time(0)
 {
-       /* constructor used for existing internal-to-session files. file must exist */
+       /* Constructor used for existing internal-to-session files.  File must exist. */
 
-       if (set_state (node)) {
+       if (set_state(node)) {
                throw failed_constructor ();
        }
        
-       if (init (_name, true)) {
+       if (init(_name, true)) {
                throw failed_constructor ();
        }
        
@@ -125,7 +125,8 @@ SMFSource::init (string pathstr, bool must_exist)
 
 /** All stamps in audio frames */
 nframes_t
-SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const
+SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t cnt,
+               nframes_t stamp_offset, nframes_t negative_stamp_offset) const
 {
        //cerr << "SMF read_unlocked " << name() << " read "
        //<< start << ", count=" << cnt << ", offset=" << stamp_offset << endl;
@@ -137,9 +138,9 @@ SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nfram
 
        // Output parameters for read_event (which will allocate scratch in buffer as needed)
        uint32_t ev_delta_t = 0;
-       uint32_t ev_type = 0;
-       uint32_t ev_size = 0;
-       uint8_t* ev_buffer = 0;
+       uint32_t ev_type    = 0;
+       uint32_t ev_size    = 0;
+       uint8_t* ev_buffer  = 0;
 
        size_t scratch_size = 0; // keep track of scratch to minimize reallocs
 
@@ -173,18 +174,20 @@ SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nfram
                        const nframes_t ev_frame_time = (nframes_t)(
                                        ((time / (double)ppqn()) * frames_per_beat)) + stamp_offset;
 
-                       if (ev_frame_time <= start + cnt)
+                       if (ev_frame_time <= start + cnt) {
                                dst.write(ev_frame_time - negative_stamp_offset, ev_type, ev_size, ev_buffer);
-                       else
+                       } else {
                                break;
+                       }
                }
 
                _read_data_count += ev_size;
 
-               if (ev_size > scratch_size)
+               if (ev_size > scratch_size) {
                        scratch_size = ev_size;
-               else
+               } else {
                        ev_size = scratch_size; // minimize realloc in read_event
+               }
        }
        
        return cnt;
@@ -200,22 +203,25 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& src, nframes_t cnt)
        Evoral::EventType type;
        uint32_t          size;
 
-       size_t buf_capacity = 4;
-       uint8_t* buf = (uint8_t*)malloc(buf_capacity);
+       size_t   buf_capacity = 4;
+       uint8_t* buf          = (uint8_t*)malloc(buf_capacity);
        
-       if (_model && ! _model->writing())
+       if (_model && ! _model->writing()) {
                _model->start_write();
+       }
 
        Evoral::MIDIEvent<double> ev(0, 0.0, 4, NULL, true);
 
        while (true) {
                bool ret = src.peek_time(&time);
-               if (!ret || time - _timeline_position > _length + cnt)
+               if (!ret || time - _timeline_position > _length + cnt) {
                        break;
+               }
 
                ret = src.read_prefix(&time, &type, &size);
-               if (!ret)
+               if (!ret) {
                        break;
+               }
 
                if (size > buf_capacity) {
                        buf_capacity = size;
@@ -233,7 +239,7 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& src, nframes_t cnt)
                
                ev.set(buf, size, time);
                ev.set_event_type(EventTypeMap::instance().midi_event_type(ev.buffer()[0]));
-               if (! (ev.is_channel_event() || ev.is_smf_meta_event() || ev.is_sysex()) ) {
+               if (!(ev.is_channel_event() || ev.is_smf_meta_event() || ev.is_sysex())) {
                        cerr << "SMFSource: WARNING: caller tried to write non SMF-Event of type "
                                        << std::hex << int(ev.buffer()[0]) << endl;
                        continue;
@@ -256,7 +262,7 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& src, nframes_t cnt)
        const nframes_t oldlen = _length;
        update_length(oldlen, cnt);
 
-       ViewDataRangeReady (_timeline_position + oldlen, cnt); /* EMIT SIGNAL */
+       ViewDataRangeReady(_timeline_position + oldlen, cnt); /* EMIT SIGNAL */
        
        return cnt;
 }
@@ -275,8 +281,7 @@ SMFSource::append_event_unlocked(EventTimeUnit unit, const Evoral::Event<double>
                        name().c_str(), ev.time(), ev.size()); 
        for (size_t i=0; i < ev.size(); ++i) {
                printf("%X ", ev.buffer()[i]);
-       }
-       printf("\n");
+       } printf("\n");
        */
        
        assert(ev.time() >= 0);
@@ -327,15 +332,11 @@ SMFSource::set_state (const XMLNode& node)
        }
 
        if ((prop = node.property (X_("flags"))) != 0) {
-
                int ival;
                sscanf (prop->value().c_str(), "0x%x", &ival);
                _flags = Flag (ival);
-
        } else {
-
                _flags = Flag (0);
-
        }
 
        assert(_name.find("/") == string::npos);
@@ -439,19 +440,7 @@ SMFSource::move_to_trash (const string trash_dir_name)
                      << endmsg;
                return -1;
        }
-#if 0
-       if (::unlink (peakpath.c_str()) != 0) {
-               PBD::error << string_compose (_("cannot remove peakfile %1 for %2 (%3)"),
-                                 peakpath, _path, strerror (errno))
-                     << endmsg;
-               /* try to back out */
-               rename (newpath.c_str(), _path.c_str());
-               return -1;
-       }
-           
-       _path = newpath;
-       peakpath = "";
-#endif 
+       
        /* file can not be removed twice, since the operation is not idempotent */
 
        _flags = Flag (_flags & ~(RemoveAtDestroy|Removable|RemovableIfEmpty));
@@ -606,7 +595,7 @@ SMFSource::set_source_name (string newname, bool destructive)
        _name = Glib::path_get_basename (newpath);
        _path = newpath;
 
-       return 0;//rename_peakfile (peak_path (_path));
+       return 0;
 }
 
 void