~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/ardour/ardour/smf_source.h

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2006 Paul Davis
 
3
    Author: David Robillard
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 
 
19
*/
 
20
 
 
21
#ifndef __ardour_smf_source_h__
 
22
#define __ardour_smf_source_h__
 
23
 
 
24
#include <cstdio>
 
25
#include <time.h>
 
26
#include "evoral/SMF.hpp"
 
27
#include "ardour/midi_source.h"
 
28
#include "ardour/file_source.h"
 
29
 
 
30
namespace Evoral { template<typename T> class Event; }
 
31
 
 
32
namespace ARDOUR {
 
33
 
 
34
template<typename T> class MidiRingBuffer;
 
35
 
 
36
/** Standard Midi File (Type 0) Source */
 
37
class SMFSource : public MidiSource, public FileSource, public Evoral::SMF {
 
38
public:
 
39
        /** Constructor for existing external-to-session files */
 
40
        SMFSource (Session& session, const std::string& path,
 
41
                        Source::Flag flags = Source::Flag(0));
 
42
 
 
43
        /** Constructor for existing in-session files */
 
44
        SMFSource (Session& session, const XMLNode&, bool must_exist = false);
 
45
 
 
46
        virtual ~SMFSource ();
 
47
 
 
48
        bool safe_file_extension (const std::string& path) const {
 
49
                return safe_midi_file_extension(path);
 
50
        }
 
51
 
 
52
        bool set_name (const std::string& newname) { return (set_source_name(newname, false) == 0); }
 
53
 
 
54
        void append_event_unlocked_beats (const Evoral::Event<Evoral::MusicalTime>& ev);
 
55
        void append_event_unlocked_frames (const Evoral::Event<framepos_t>& ev, framepos_t source_start);
 
56
 
 
57
        void mark_streaming_midi_write_started (NoteMode mode);
 
58
        void mark_streaming_write_completed ();
 
59
        void mark_midi_streaming_write_completed (Evoral::Sequence<Evoral::MusicalTime>::StuckNoteOption, Evoral::MusicalTime when = 0);
 
60
 
 
61
        XMLNode& get_state ();
 
62
        int set_state (const XMLNode&, int version);
 
63
 
 
64
        void load_model (bool lock=true, bool force_reload=false);
 
65
        void destroy_model ();
 
66
 
 
67
        void flush_midi ();
 
68
        void ensure_disk_file ();
 
69
 
 
70
        static bool safe_midi_file_extension (const std::string& path);
 
71
 
 
72
  protected:
 
73
        void set_path (const std::string& newpath);
 
74
 
 
75
  private:
 
76
        int open_for_write ();
 
77
 
 
78
        framecnt_t read_unlocked (Evoral::EventSink<framepos_t>& dst,
 
79
                                  framepos_t                     position,
 
80
                                  framepos_t                     start,
 
81
                                  framecnt_t                     cnt,
 
82
                                  MidiStateTracker*              tracker) const;
 
83
 
 
84
        framecnt_t write_unlocked (MidiRingBuffer<framepos_t>& src,
 
85
                                   framepos_t                  position,
 
86
                                   framecnt_t                  cnt);
 
87
 
 
88
        double    _last_ev_time_beats;
 
89
        framepos_t _last_ev_time_frames;
 
90
        /** end time (start + duration) of last call to read_unlocked */
 
91
        mutable framepos_t _smf_last_read_end;
 
92
        /** time (in SMF ticks, 1 tick per _ppqn) of the last event read by read_unlocked */
 
93
        mutable framepos_t _smf_last_read_time;
 
94
};
 
95
 
 
96
}; /* namespace ARDOUR */
 
97
 
 
98
#endif /* __ardour_smf_source_h__ */
 
99