remove Glib::ustring from libardour; allow any characters except '/' and '\' in paths...
[ardour.git] / libs / ardour / ardour / smf_source.h
index 83bc47d7d372b517a177ba696c1be32eeacc18ec..165e03e483a2e0670ff9cae53822e56c94108242 100644 (file)
 
 */
 
-#ifndef __ardour_smf_filesource_h__ 
-#define __ardour_smf_filesource_h__
+#ifndef __ardour_smf_source_h__
+#define __ardour_smf_source_h__
 
+#include <cstdio>
 #include <time.h>
+#include "evoral/SMF.hpp"
+#include "ardour/midi_source.h"
+#include "ardour/file_source.h"
 
-#include <ardour/midi_source.h>
+namespace Evoral { template<typename T> class Event; }
 
 namespace ARDOUR {
 
+template<typename T> class MidiRingBuffer;
+
 /** Standard Midi File (Type 0) Source */
-class SMFSource : public MidiSource {
-  public:
-       enum Flag {
-               Writable = 0x1,
-               CanRename = 0x2,
-               Broadcast = 0x4,
-               Removable = 0x8,
-               RemovableIfEmpty = 0x10,
-               RemoveAtDestroy = 0x20,
-               BuildPeaks = 0x40
-       };
-       
+class SMFSource : public MidiSource, public FileSource, public Evoral::SMF {
+public:
        /** Constructor for existing external-to-session files */
-       SMFSource (std::string path, Flag flags = Flag(0));
+       SMFSource (Session& session, const std::string& path, 
+                       Source::Flag flags = Source::Flag(0));
 
-       /* Constructor for existing in-session files */
-       SMFSource (const XMLNode&);
+       /** Constructor for existing in-session files */
+       SMFSource (Session& session, const XMLNode&, bool must_exist = false);
 
        virtual ~SMFSource ();
 
-       int set_name (string newname, bool destructive);
-
-       string path() const { return _path; }
+       bool safe_file_extension (const std::string& path) const {
+               return safe_midi_file_extension(path);
+       }
 
-       void set_allow_remove_if_empty (bool yn);
-       void mark_for_remove();
+       bool set_name (const std::string& newname) { return (set_source_name(newname, false) == 0); }
 
-       int update_header (jack_nframes_t when, struct tm&, time_t);
-       int flush_header ();
+       void append_event_unlocked_beats (const Evoral::Event<Evoral::MusicalTime>& ev);
+       void append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, sframes_t source_start);
 
-       int move_to_trash (const string trash_dir_name);
-
-       static bool is_empty (string path);
+       void mark_streaming_midi_write_started (NoteMode mode, sframes_t start_time);
        void mark_streaming_write_completed ();
 
-       void   mark_take (string);
-       string take_id() const { return _take_id; }
-
-       static void set_search_path (string);
-       static void set_header_position_offset (jack_nframes_t offset, bool negative);
-
        XMLNode& get_state ();
-       int set_state (const XMLNode&);
+       int set_state (const XMLNode&, int version);
 
-  protected:
+       void load_model (bool lock=true, bool force_reload=false);
+       void destroy_model ();
 
-       int init (string idstr, bool must_exist);
+       void flush_midi ();
 
-       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);
+       static void set_header_position_offset (nframes_t offset, bool negative);
 
-       bool find (std::string path, bool must_exist, bool& is_new);
-       bool removable() const;
-       bool writable() const { return _flags & Writable; }
-       
-       uint16_t      _channel;
-       string        _path;
-       Flag          _flags;
-       string        _take_id;
-       bool          _allow_remove_if_empty;
-       uint64_t      _timeline_position;
+       static bool safe_midi_file_extension (const std::string& path);
 
-       static string _search_path;
+  protected:
+        void set_path (const std::string& newpath);
+        
+  private:
+       nframes_t read_unlocked (Evoral::EventSink<nframes_t>& dst,
+                                sframes_t position,
+                                sframes_t start,
+                                nframes_t cnt,
+                                MidiStateTracker* tracker) const;
+
+       nframes_t write_unlocked (MidiRingBuffer<nframes_t>& src,
+                       sframes_t position,
+                       nframes_t cnt);
+
+       double    _last_ev_time_beats;
+       sframes_t _last_ev_time_frames;
+       /** end time (start + duration) of last call to read_unlocked */
+       mutable sframes_t _smf_last_read_end;
+       /** time (in SMF ticks, 1 tick per _ppqn) of the last event read by read_unlocked */
+       mutable sframes_t _smf_last_read_time;
 };
 
 }; /* namespace ARDOUR */
 
-#endif /* __ardour_smf_filesource_h__ */
+#endif /* __ardour_smf_source_h__ */