~ubuntu-branches/ubuntu/lucid/ardour/lucid-proposed

« back to all changes in this revision

Viewing changes to libs/ardour/region.cc

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-02-07 20:51:55 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080207205155-xzi5lq5s2o1okvx8
Tags: 1:2.3.1-1
* New upstream release
* debian/control:
   - build-depend on libfftw3-dev (Closes: #463803)
   - added Homepage, Vcs-Svn, Vcs-Browser
* debian/patches
   - dropped 50-soundtouch.patch (fixed upstream)
   - updated 80_ardourino.patch
   - dropped unused patches from source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <cmath>
22
22
#include <climits>
23
23
#include <algorithm>
 
24
#include <sstream>
24
25
 
25
26
#include <sigc++/bind.h>
26
27
#include <sigc++/class_slot.h>
28
29
#include <glibmm/thread.h>
29
30
#include <pbd/xml++.h>
30
31
#include <pbd/stacktrace.h>
 
32
#include <pbd/enumwriter.h>
31
33
 
32
34
#include <ardour/region.h>
33
35
#include <ardour/playlist.h>
34
36
#include <ardour/session.h>
 
37
#include <ardour/tempo.h>
35
38
#include <ardour/region_factory.h>
36
39
 
37
40
#include "i18n.h"
56
59
        _read_data_count = 0;
57
60
        _frozen = 0;
58
61
        pending_changed = Change (0);
59
 
 
 
62
        valid_transients = false;
60
63
        _name = name;
61
64
        _start = start; 
62
65
        _sync_position = _start;
72
75
        _read_data_count = 0;
73
76
        _first_edit = EditChangesNothing;
74
77
        _last_layer_op = 0;
 
78
        _positional_lock_style = AudioTime;
75
79
}
76
80
 
77
81
Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags)
81
85
        _frozen = 0;
82
86
        pending_changed = Change (0);
83
87
        _read_data_count = 0;
 
88
        valid_transients = false;
84
89
 
85
90
        _start = other->_start + offset; 
86
91
        if (other->_sync_position < offset) {
101
106
        _flags = Flag (flags & ~(Locked|WholeFile|Hidden));
102
107
        _first_edit = EditChangesNothing;
103
108
        _last_layer_op = 0;
 
109
        _positional_lock_style = AudioTime;
104
110
}
105
111
 
106
112
Region::Region (boost::shared_ptr<const Region> other)
110
116
        _frozen = 0;
111
117
        pending_changed = Change (0);
112
118
        _read_data_count = 0;
 
119
        valid_transients = false;
113
120
 
114
121
        _first_edit = EditChangesID;
115
122
        other->_first_edit = EditChangesName;
134
141
        _layer = other->_layer; 
135
142
        _flags = Flag (other->_flags & ~Locked);
136
143
        _last_layer_op = other->_last_layer_op;
 
144
        _positional_lock_style = AudioTime;
137
145
}
138
146
 
139
147
Region::Region (const XMLNode& node)
140
148
{
141
149
        _frozen = 0;
142
150
        pending_changed = Change (0);
 
151
        valid_transients = false;
143
152
        _read_data_count = 0;
144
153
        _start = 0; 
145
154
        _sync_position = _start;
151
160
        _layer = 0;
152
161
        _flags = Flag (0);
153
162
        _first_edit = EditChangesNothing;
 
163
        _positional_lock_style = AudioTime;
154
164
 
155
165
        if (set_state (node)) {
156
166
                throw failed_constructor();
206
216
 
207
217
                first_edit ();
208
218
                maybe_uncopy ();
 
219
                invalidate_transients ();
209
220
 
210
221
                if (!_frozen) {
211
222
                        recompute_at_end ();
283
294
}
284
295
 
285
296
void
 
297
Region::set_position_lock_style (PositionLockStyle ps)
 
298
{
 
299
        boost::shared_ptr<Playlist> pl (playlist());
 
300
 
 
301
        if (!pl) {
 
302
                return;
 
303
        }
 
304
 
 
305
        _positional_lock_style = ps;
 
306
 
 
307
        if (_positional_lock_style == MusicTime) {
 
308
                pl->session().tempo_map().bbt_time (_position, _bbt_time);
 
309
        }
 
310
        
 
311
}
 
312
 
 
313
void
 
314
Region::update_position_after_tempo_map_change ()
 
315
{
 
316
        boost::shared_ptr<Playlist> pl (playlist());
 
317
        
 
318
        if (!pl || _positional_lock_style != MusicTime) {
 
319
                return;
 
320
        }
 
321
 
 
322
        TempoMap& map (pl->session().tempo_map());
 
323
        nframes_t pos = map.frame_time (_bbt_time);
 
324
        set_position_internal (pos, false);
 
325
}
 
326
 
 
327
void
286
328
Region::set_position (nframes_t pos, void *src)
287
329
{
288
330
        if (_flags & Locked) {
289
331
                return;
290
332
        }
291
333
 
 
334
        set_position_internal (pos, true);
 
335
}
 
336
 
 
337
void
 
338
Region::set_position_internal (nframes_t pos, bool allow_bbt_recompute)
 
339
{
292
340
        if (_position != pos) {
293
341
                _last_position = _position;
294
342
                _position = pos;
303
351
                        _last_length = _length;
304
352
                        _length = max_frames - _position;
305
353
                }
 
354
 
 
355
                if (allow_bbt_recompute && _positional_lock_style == MusicTime) {
 
356
                        boost::shared_ptr<Playlist> pl (playlist());
 
357
                        if (pl) {
 
358
                                pl->session().tempo_map().bbt_time (_position, _bbt_time);
 
359
                        }
 
360
                }
 
361
 
 
362
                invalidate_transients ();
306
363
        }
307
364
 
308
365
        /* do this even if the position is the same. this helps out
396
453
                _start = pos;
397
454
                _flags = Region::Flag (_flags & ~WholeFile);
398
455
                first_edit ();
 
456
                invalidate_transients ();
399
457
 
400
458
                send_change (StartChanged);
401
459
        }
706
764
        // cerr << "adjusting pos = " << pos << " to sync at " << _sync_position << " offset = " << offset << " with dir = " << sync_dir << endl;
707
765
        
708
766
        if (sync_dir > 0) {
 
767
                if (pos > offset) {
 
768
                        pos -= offset;
 
769
                } else {
 
770
                        pos = 0;
 
771
                }
 
772
        } else {
709
773
                if (max_frames - pos > offset) {
710
 
                        pos -= offset;
711
 
                }
712
 
        } else {
713
 
                if (pos > offset) {
714
774
                        pos += offset;
715
 
                } else {
716
 
                        pos = 0;
717
775
                }
718
776
        }
719
777
 
793
851
        node->add_property ("length", buf);
794
852
        snprintf (buf, sizeof (buf), "%u", _position);
795
853
        node->add_property ("position", buf);
796
 
        snprintf (buf, sizeof (buf), "%lu", _ancestral_start);
 
854
        snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_start);
797
855
        node->add_property ("ancestral-start", buf);
798
 
        snprintf (buf, sizeof (buf), "%lu", _ancestral_length);
 
856
        snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_length);
799
857
        node->add_property ("ancestral-length", buf);
800
858
        snprintf (buf, sizeof (buf), "%.12g", _stretch);
801
859
        node->add_property ("stretch", buf);
826
884
        snprintf (buf, sizeof (buf), "%" PRIu32, _sync_position);
827
885
        node->add_property ("sync-position", buf);
828
886
 
 
887
        if (_positional_lock_style != AudioTime) {
 
888
                node->add_property ("positional-lock-style", enum_2_string (_positional_lock_style));
 
889
                stringstream str;
 
890
                str << _bbt_time;
 
891
                node->add_property ("bbt-position", str.str());
 
892
        }
 
893
 
829
894
        return *node;
830
895
}
831
896
 
908
973
                _sync_position = _start;
909
974
        }
910
975
 
 
976
        if ((prop = node.property ("positional-lock-style")) != 0) {
 
977
                _positional_lock_style = PositionLockStyle (string_2_enum (prop->value(), _positional_lock_style));
 
978
 
 
979
                if (_positional_lock_style == MusicTime) {
 
980
                        if ((prop = node.property ("bbt-position")) == 0) {
 
981
                                /* missing BBT info, revert to audio time locking */
 
982
                                _positional_lock_style = AudioTime;
 
983
                        } else {
 
984
                                if (sscanf (prop->value().c_str(), "%d|%d|%d", 
 
985
                                            &_bbt_time.bars,
 
986
                                            &_bbt_time.beats,
 
987
                                            &_bbt_time.ticks) != 3) {
 
988
                                        _positional_lock_style = AudioTime;
 
989
                                }
 
990
                        }
 
991
                }
 
992
                        
 
993
        } else {
 
994
                _positional_lock_style = AudioTime;
 
995
        }
 
996
 
911
997
        /* XXX FIRST EDIT !!! */
912
998
        
913
999
        /* these 3 properties never change as a result of any editing */
1070
1156
{
1071
1157
        return size_equivalent (other) && source_equivalent (other) && _name == other->_name;
1072
1158
}
 
1159
 
 
1160
void
 
1161
Region::invalidate_transients ()
 
1162
{
 
1163
        valid_transients = false;
 
1164
        _transients.clear ();
 
1165
}
 
1166