remove i/ofstream from libardour
authorRobin Gareus <robin@gareus.org>
Mon, 5 Oct 2015 19:43:44 +0000 (21:43 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 5 Oct 2015 20:15:17 +0000 (22:15 +0200)
except:
 * audio-unit (ifstream is known to work on OSX)
 * evoral curve algorithm debugger
 * cycle-timer debug code
 * export_handler's CDMarker  -> TODO

libs/ardour/ardour/cycle_timer.h
libs/ardour/audioanalyser.cc
libs/ardour/automatable.cc
libs/ardour/cycle_timer.cc
libs/ardour/recent_sessions.cc
libs/ardour/source.cc
libs/backends/jack/jack_utils.cc
libs/gtkmm2ext/cursors.cc
libs/surfaces/osc/osc.cc

index ac19abda1ef09c1796beb56809422617703b8d3e..54a2d1d8f2d27f47df119a55902e42828f721312 100644 (file)
@@ -70,7 +70,9 @@ public:
        StoringTimer (int);
        void ref ();
        void check (int);
+#ifndef NDEBUG
        void dump (std::string const &);
+#endif
 
 private:
        cycles_t _current_ref;
index ac00a55eadc39e68355060af70c9741cebb90d37..24aaa514371bbbe4e21f18c36a9461712468cbd3 100644 (file)
@@ -102,7 +102,7 @@ AudioAnalyser::reset ()
 int
 AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
 {
-       ofstream ofile;
+       stringstream outss;
        Plugin::FeatureSet features;
        int ret = -1;
        bool done = false;
@@ -110,20 +110,6 @@ AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
        framecnt_t len = src->readable_length();
        framepos_t pos = 0;
        float* bufs[1] = { 0 };
-       string tmp_path;
-
-       if (!path.empty()) {
-
-               /* store data in tmp file, not the real one */
-
-               tmp_path = path;
-               tmp_path += ".tmp";
-
-               ofile.open (tmp_path.c_str());
-               if (!ofile) {
-                       goto out;
-               }
-       }
 
        data = new Sample[bufsize];
        bufs[0] = data;
@@ -148,7 +134,7 @@ AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
 
                features = plugin->process (bufs, RealTime::fromSeconds ((double) pos / sample_rate));
 
-               if (use_features (features, (path.empty() ? 0 : &ofile))) {
+               if (use_features (features, (path.empty() ? 0 : &outss))) {
                        goto out;
                }
 
@@ -163,21 +149,15 @@ AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
 
        features = plugin->getRemainingFeatures ();
 
-       if (use_features (features, (path.empty() ? &ofile : 0))) {
+       if (use_features (features, (path.empty() ? 0 : &outss))) {
                goto out;
        }
 
        ret = 0;
 
   out:
-       /* works even if it has not been opened */
-       ofile.close ();
-
-       if (ret) {
-               g_remove (tmp_path.c_str());
-       } else if (!path.empty()) {
-               /* move the data file to the requested path */
-               g_rename (tmp_path.c_str(), path.c_str());
+       if (!ret) {
+               g_file_set_contents (path.c_str(), outss.str().c_str(), -1, NULL);
        }
 
        delete [] data;
index a2ce81acca360acd203d97fcb120403da65572ce..b26052d59bf59fcb7e66314f158fc5437dcb7df5 100644 (file)
 
 */
 
-#include <fstream>
 #include <cstdio>
 #include <errno.h>
 
+#include <pbd/gstdio_compat.h>
 #include <glibmm/miscutils.h>
 
 #include "pbd/error.h"
@@ -98,7 +98,8 @@ Automatable::load_automation (const string& path)
                fullpath = _a_session.automation_dir();
                fullpath += path;
        }
-       ifstream in (fullpath.c_str());
+
+       FILE * in = g_fopen (fullpath.c_str (), "rb");
 
        if (!in) {
                warning << string_compose(_("cannot open %2 to load automation data (%3)")
@@ -110,14 +111,17 @@ Automatable::load_automation (const string& path)
        set<Evoral::Parameter> tosave;
        controls().clear ();
 
-       while (in) {
+       while (!feof(in)) {
                double when;
                double value;
                uint32_t port;
 
-               in >> port;  if (!in) break;
-               in >> when;  if (!in) goto bad;
-               in >> value; if (!in) goto bad;
+               if (3 != fscanf (in, "%d %lf %lf", &port, &when, &value)) {
+                       if (feof(in)) {
+                               break;
+                       }
+                       goto bad;
+               }
 
                Evoral::Parameter param(PluginAutomation, 0, port);
                /* FIXME: this is legacy and only used for plugin inserts?  I think? */
@@ -125,12 +129,14 @@ Automatable::load_automation (const string& path)
                c->list()->add (when, value);
                tosave.insert (param);
        }
+       ::fclose (in);
 
        return 0;
 
   bad:
        error << string_compose(_("cannot load automation data from %2"), fullpath) << endmsg;
        controls().clear ();
+       ::fclose (in);
        return -1;
 }
 
index ad91fa68744ffe49ac17165d295f7d205bab7432..a86124c5555901b4f4e1f413222c6ff07dac4928 100644 (file)
@@ -86,7 +86,7 @@ StoringTimer::StoringTimer (int N)
        _points = 0;
 }
 
-
+#ifndef NDEBUG
 void
 StoringTimer::dump (string const & file)
 {
@@ -98,6 +98,7 @@ StoringTimer::dump (string const & file)
                f << _point[i] << " " << _ref[i] << " " << _value[i] << "\n";
        }
 }
+#endif
 
 void
 StoringTimer::ref ()
index 22244c80ba7ae5f6a881c92fcf725cbb6a93509e..d08ebfec00647cc670bca6bdae9b52f439b48ba9 100644 (file)
@@ -19,8 +19,6 @@
 
 #include <cstring>
 #include <cerrno>
-#include <fstream>
-#include <iostream>
 #include <sstream>
 #include <algorithm>
 
@@ -163,12 +161,6 @@ ARDOUR::write_recent_sessions (RecentSessions& rs)
 
        {
                stringstream recent;
-               //ofstream recent (fout);
-
-               // if (!recent) {
-               //      fclose (fout);
-               //      return -1;
-               // }
 
                for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
                        recent << (*i).first << '\n' << (*i).second << endl;
index b9ea6ee78a912f5ac75e020509fd94faf3d76c59..b3476ec8f4427fd3040015b1f8da8010410c1b1a 100644 (file)
@@ -25,8 +25,8 @@
 #include <cmath>
 #include <iomanip>
 #include <algorithm>
-#include <fstream>
 
+#include <pbd/gstdio_compat.h>
 #include <glibmm/threads.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/fileutils.h>
@@ -187,27 +187,23 @@ Source::set_been_analysed (bool yn)
 int
 Source::load_transients (const string& path)
 {
-       ifstream file (path.c_str());
-
-       if (!file) {
+       FILE *tf;
+       if (! (tf = g_fopen (path.c_str (), "rb"))) {
                return -1;
        }
 
        transients.clear ();
-
-       stringstream strstr;
-       double val;
-
-       while (file.good()) {
-               file >> val;
-
-               if (!file.fail()) {
-                       framepos_t frame = (framepos_t) floor (val * _session.frame_rate());
-                       transients.push_back (frame);
+       while (!feof (tf) && !ferror(tf)) {
+               double val;
+               if (1 != fscanf (tf, "%lf", &val)) {
+                       break;
                }
+
+               framepos_t frame = (framepos_t) floor (val * _session.frame_rate());
+               transients.push_back (frame);
        }
 
-       return 0;
+       ::fclose (tf);
 }
 
 string
index 029b922f7343e7d7658dd37a24e3c2888f54d903..fa8a1aee145ee32849ec5cba1156d01204642018 100644 (file)
 #include <portaudio.h>
 #endif
 
-#include <fstream>
-
 #include <boost/scoped_ptr.hpp>
 
+#include "pbd/gstdio_compat.h"
 #include <glibmm/miscutils.h>
 
 #include "pbd/epa.h"
@@ -927,15 +926,10 @@ ARDOUR::get_jack_server_user_config_file_path ()
 bool
 ARDOUR::write_jack_config_file (const std::string& config_file_path, const string& command_line)
 {
-       ofstream jackdrc (config_file_path.c_str());
-
-       if (!jackdrc) {
+       if (!g_file_set_contents (config_file_path.c_str(), command_line.c_str(), -1, NULL)) {
                error << string_compose (_("cannot open JACK rc file %1 to store parameters"), config_file_path) << endmsg;
                return false;
        }
-
-       jackdrc << command_line << endl;
-       jackdrc.close ();
        return true;
 }
 
index 9948fc667f1347c0782b3a42bdbd941b86eaa538..f8862835f68af5680197af34d2adccf6178ffa7c 100644 (file)
@@ -18,8 +18,8 @@
 */
 
 #include <sstream>
-#include <fstream>
 
+#include "pbd/gstdio_compat.h"
 #include "pbd/error.h"
 #include "pbd/compose.h"
 
@@ -41,13 +41,13 @@ CursorInfo::CursorInfo (const std::string& n, int hotspot_x, int hotspot_y)
 int
 CursorInfo::load_cursor_info (const std::string& path)
 {
-        std::ifstream infofile (path.c_str());
-
-        if (!infofile) {
-                return -1;
-        }
+       gchar *buf = NULL;
+       if (!g_file_get_contents (path.c_str(), &buf, NULL, NULL))  {
+               return -1;
+       }
+       std::stringstream infofile (buf);
+       g_free (buf);
 
-        std::stringstream s;
         std::string name;
         int x;
         int y;
index fade3b20b760fc08c4cb5426268cd0e21368abdc..9c775121daae1c645708fffabb17d466033cc19b 100644 (file)
@@ -17,8 +17,6 @@
  *
  */
 
-#include <iostream>
-#include <fstream>
 #include <cstdio>
 #include <cstdlib>
 #include <cerrno>
@@ -208,15 +206,8 @@ OSC::start ()
        std::string url_file;
 
        if (find_file (ardour_config_search_path(), "osc_url", url_file)) {
-
                _osc_url_file = url_file;
-               ofstream urlfile;
-               urlfile.open(_osc_url_file.c_str(), ios::trunc);
-
-               if (urlfile) {
-                       urlfile << get_server_url () << endl;
-                       urlfile.close();
-               } else {
+               if (g_file_set_contents (_osc_url_file.c_str(), get_server_url().c_str(), -1, NULL)) {
                        cerr << "Couldn't write '" <<  _osc_url_file << "'" <<endl;
                }
        }