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

« back to all changes in this revision

Viewing changes to libs/ardour/session.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-07-29 11:27:04 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20080729112704-x1rmgb4tjotjyu5u
Tags: 1:2.5-0ubuntu1
* New upstream release.
* debian/patches/s390-FTBFS.patch: Dropped, as it fails to apply, and
  Ubuntu doesn't concern itself with s390.
* debian/control:
  - Fix package description, thanks to the patch in Debian bug #485892.
  - Metadata cleanup and sync control/control.in files.
  - Add libaubio-dev to Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
sigc::signal<void> Session::AutoBindingOff;
119
119
 
120
120
 
 
121
sigc::signal<void, std::string, std::string> Session::Exported;
 
122
 
121
123
int
122
124
Session::find_session (string str, string& path, string& snapshot, bool& isnew)
123
125
{
282
284
          diskstreams (new DiskstreamList),
283
285
          routes (new RouteList),
284
286
          auditioner ((Auditioner*) 0),
 
287
          _total_free_4k_blocks (0),
285
288
          _click_io ((IO*) 0),
286
289
          main_outs (0)
287
290
{
344
347
          midi_requests (16),
345
348
          diskstreams (new DiskstreamList),
346
349
          routes (new RouteList),
 
350
          _total_free_4k_blocks (0),
347
351
          main_outs (0)
348
352
 
349
353
{
1249
1253
                        set_loop = true;
1250
1254
                }
1251
1255
                
 
1256
                if (location->is_start()) {
 
1257
                        start_location = location;
 
1258
                }
 
1259
                if (location->is_end()) {
 
1260
                        end_location = location;
 
1261
                }
1252
1262
        }
1253
1263
 
1254
1264
        if (!set_loop) {
2437
2447
        boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
2438
2448
 
2439
2449
        for (DiskstreamList::const_iterator i = dsl->begin(); i != dsl->end(); ++i) {
 
2450
                if ((*i)->destructive())  //ignore tape tracks when getting max extents
 
2451
                        continue;
2440
2452
                boost::shared_ptr<Playlist> pl = (*i)->playlist();
2441
2453
                if ((me = pl->get_maximum_extent()) > max) {
2442
2454
                        max = me;
2528
2540
}
2529
2541
 
2530
2542
int
2531
 
Session::region_name (string& result, string base, bool newlevel) const
 
2543
Session::region_name (string& result, string base, bool newlevel)
2532
2544
{
2533
2545
        char buf[16];
2534
2546
        string subbase;
2538
2550
                Glib::Mutex::Lock lm (region_lock);
2539
2551
 
2540
2552
                snprintf (buf, sizeof (buf), "%d", (int)audio_regions.size() + 1);
2541
 
 
2542
 
                
2543
2553
                result = "region.";
2544
2554
                result += buf;
2545
2555
 
2546
2556
        } else {
2547
2557
 
2548
 
                /* XXX this is going to be slow. optimize me later */
2549
 
                
2550
2558
                if (newlevel) {
2551
2559
                        subbase = base;
2552
2560
                } else {
2559
2567
                        subbase = base.substr (0, pos);
2560
2568
 
2561
2569
                }
2562
 
 
2563
 
                bool name_taken = true;
2564
2570
                
2565
2571
                {
2566
2572
                        Glib::Mutex::Lock lm (region_lock);
2567
 
                        
2568
 
                        for (int n = 1; n < 5000; ++n) {
2569
 
                                
2570
 
                                result = subbase;
2571
 
                                snprintf (buf, sizeof (buf), ".%d", n);
 
2573
 
 
2574
                        map<string,uint32_t>::iterator x;
 
2575
 
 
2576
                        result = subbase;
 
2577
 
 
2578
                        if ((x = region_name_map.find (subbase)) == region_name_map.end()) {
 
2579
                                result += ".1";
 
2580
                                region_name_map[subbase] = 1;
 
2581
                        } else {
 
2582
                                x->second++;
 
2583
                                snprintf (buf, sizeof (buf), ".%d", x->second);
2572
2584
                                result += buf;
2573
 
                                
2574
 
                                name_taken = false;
2575
 
                                
2576
 
                                for (AudioRegionList::const_iterator i = audio_regions.begin(); i != audio_regions.end(); ++i) {
2577
 
                                        if (i->second->name() == result) {
2578
 
                                                name_taken = true;
2579
 
                                                break;
2580
 
                                        }
2581
 
                                }
2582
 
                                
2583
 
                                if (!name_taken) {
2584
 
                                        break;
2585
 
                                }
2586
2585
                        }
2587
2586
                }
2588
 
                        
2589
 
                if (name_taken) {
2590
 
                        fatal << string_compose(_("too many regions with names like %1"), base) << endmsg;
2591
 
                        /*NOTREACHED*/
2592
 
                }
2593
2587
        }
 
2588
 
2594
2589
        return 0;
2595
2590
}       
2596
2591
 
2642
2637
                                        
2643
2638
                                        pair<AudioRegionList::iterator,bool> x = audio_regions.insert (entry);
2644
2639
                                        
2645
 
                                        
2646
2640
                                        if (!x.second) {
2647
2641
                                                return;
2648
2642
                                        }
2665
2659
           add the region to the region list.
2666
2660
        */
2667
2661
        
2668
 
        set_dirty();
 
2662
        set_dirty ();
2669
2663
        
2670
2664
        if (added) {
2671
2665
 
2691
2685
 
2692
2686
                        region->StateChanged.connect (sigc::bind (mem_fun (*this, &Session::region_changed), boost::weak_ptr<Region>(region)));
2693
2687
                        region->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_region), boost::weak_ptr<Region>(region)));
 
2688
 
 
2689
                        update_region_name_map (region);
2694
2690
                }
2695
 
                
 
2691
 
2696
2692
                if (!v.empty()) {
2697
2693
                        AudioRegionsAdded (v); /* EMIT SIGNAL */
2698
2694
                }
2700
2696
}
2701
2697
 
2702
2698
void
 
2699
Session::update_region_name_map (boost::shared_ptr<Region> region)
 
2700
{
 
2701
        string::size_type last_period = region->name().find_last_of ('.');
 
2702
        
 
2703
        if (last_period != string::npos && last_period < region->name().length() - 1) {
 
2704
                
 
2705
                string base = region->name().substr (0, last_period);
 
2706
                string number = region->name().substr (last_period+1);
 
2707
                map<string,uint32_t>::iterator x;
 
2708
                
 
2709
                /* note that if there is no number, we get zero from atoi,
 
2710
                   which is just fine
 
2711
                */
 
2712
                
 
2713
                region_name_map[base] = atoi (number);
 
2714
        }
 
2715
}
 
2716
 
 
2717
void
2703
2718
Session::region_changed (Change what_changed, boost::weak_ptr<Region> weak_region)
2704
2719
{
2705
2720
        boost::shared_ptr<Region> region (weak_region.lock ());
2712
2727
                /* relay hidden changes */
2713
2728
                RegionHiddenChange (region);
2714
2729
        }
 
2730
 
 
2731
        if (what_changed & NameChanged) {
 
2732
                update_region_name_map (region);
 
2733
        }
2715
2734
}
2716
2735
 
2717
2736
void
2960
2979
Glib::ustring
2961
2980
Session::peak_path (Glib::ustring base) const
2962
2981
{
2963
 
        Glib::ustring res;
2964
 
        
2965
 
        res = peak_dir ();
2966
 
        res += base;
2967
 
        res += ".peak";
2968
 
 
2969
 
        return res;
 
2982
        return Glib::build_filename(peak_dir (), base + ".peak");
2970
2983
}
2971
2984
 
2972
2985
string
3718
3731
#ifdef NO_POSIX_MEMALIGN
3719
3732
                p =  (Sample *) malloc(current_block_size * sizeof(Sample));
3720
3733
#else
3721
 
                if (posix_memalign((void **)&p,CPU_CACHE_ALIGN,current_block_size * 4) != 0) {
 
3734
                if (posix_memalign((void **)&p,CPU_CACHE_ALIGN,current_block_size * sizeof(Sample)) != 0) {
3722
3735
                        fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"),
3723
3736
                                                 current_block_size, sizeof (Sample), strerror (errno))
3724
3737
                              << endmsg;
3936
3949
        return 0;
3937
3950
}
3938
3951
 
3939
 
int
3940
 
Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t len,      
 
3952
boost::shared_ptr<Region>
 
3953
Session::write_one_audio_track (AudioTrack& track, nframes_t start, nframes_t end,      
3941
3954
                               bool overwrite, vector<boost::shared_ptr<AudioSource> >& srcs, InterThreadInfo& itt)
3942
3955
{
3943
 
        int ret = -1;
 
3956
        boost::shared_ptr<Region> result;
3944
3957
        boost::shared_ptr<Playlist> playlist;
3945
3958
        boost::shared_ptr<AudioFileSource> fsource;
3946
3959
        uint32_t x;
3950
3963
        nframes_t position;
3951
3964
        nframes_t this_chunk;
3952
3965
        nframes_t to_do;
 
3966
        nframes_t len = end - start;
3953
3967
        vector<Sample*> buffers;
3954
3968
 
 
3969
        if (end <= start) {
 
3970
                error << string_compose (_("Cannot write a range where end <= start (e.g. %1 <= %2)"),
 
3971
                                         end, start) << endmsg;
 
3972
                return result;
 
3973
        }
 
3974
 
3955
3975
        // any bigger than this seems to cause stack overflows in called functions
3956
3976
        const nframes_t chunk_size = (128 * 1024)/4;
3957
3977
 
4064
4084
                
4065
4085
                /* construct a region to represent the bounced material */
4066
4086
 
4067
 
                boost::shared_ptr<Region> aregion = RegionFactory::create (srcs, 0, srcs.front()->length(), 
4068
 
                                                                           region_name_from_path (srcs.front()->name(), true));
4069
 
 
4070
 
                ret = 0;
 
4087
                result = RegionFactory::create (srcs, 0, srcs.front()->length(), 
 
4088
                                                region_name_from_path (srcs.front()->name(), true));
4071
4089
        }
4072
4090
                
4073
4091
  out:
4074
 
        if (ret) {
 
4092
        if (!result) {
4075
4093
                for (vector<boost::shared_ptr<AudioSource> >::iterator src = srcs.begin(); src != srcs.end(); ++src) {
4076
4094
                        boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*src);
4077
4095
 
4078
4096
                        if (afs) {
4079
4097
                                afs->mark_for_remove ();
4080
4098
                        }
4081
 
 
 
4099
                        
4082
4100
                        (*src)->drop_references ();
4083
4101
                }
4084
4102
 
4089
4107
        }
4090
4108
 
4091
4109
        for (vector<Sample*>::iterator i = buffers.begin(); i != buffers.end(); ++i) {
4092
 
                free(*i);
 
4110
                free (*i);
4093
4111
        }
4094
4112
 
4095
4113
        g_atomic_int_set (&processing_prohibited, 0);
4096
4114
 
4097
4115
        itt.done = true;
4098
4116
 
4099
 
        return ret;
 
4117
        return result;
4100
4118
}
4101
4119
 
4102
4120
vector<Sample*>&
4118
4136
#ifdef NO_POSIX_MEMALIGN
4119
4137
                        p =  (Sample *) malloc(current_block_size * sizeof(Sample));
4120
4138
#else
4121
 
                        if (posix_memalign((void **)&p,CPU_CACHE_ALIGN,current_block_size * 4) != 0) {
 
4139
                        if (posix_memalign((void **)&p,CPU_CACHE_ALIGN,current_block_size * sizeof(Sample)) != 0) {
4122
4140
                                fatal << string_compose (_("Memory allocation error: posix_memalign (%1 * %2) failed (%3)"),
4123
4141
                                                         current_block_size, sizeof (Sample), strerror (errno))
4124
4142
                                      << endmsg;