-// FIXME: Merge this with audiofilesource somehow (make a generic filesource?)
-bool
-SMFSource::find (string pathstr, bool must_exist, bool& isnew)
-{
- bool ret = false;
-
- isnew = false;
-
- if (pathstr[0] != '/') {
-
- /* non-absolute pathname: find pathstr in search path */
-
- vector<string> dirs;
- int cnt;
- string fullpath;
- string keeppath;
-
- if (_search_path.length() == 0) {
- PBD::error << _("FileSource: search path not set") << endmsg;
- goto out;
- }
-
- split (_search_path, dirs, ':');
-
- cnt = 0;
-
- for (vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
- fullpath = *i;
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
- fullpath += pathstr;
-
- if (access (fullpath.c_str(), R_OK) == 0) {
- keeppath = fullpath;
- ++cnt;
- }
- }
-
- if (cnt > 1) {
-
- PBD::error << string_compose (_("FileSource: \"%1\" is ambigous when searching %2\n\t"), pathstr, _search_path) << endmsg;
- goto out;
-
- } else if (cnt == 0) {
-
- if (must_exist) {
- PBD::error << string_compose(_("Filesource: cannot find required file (%1): while searching %2"), pathstr, _search_path) << endmsg;
- goto out;
- } else {
- isnew = true;
- }
- }
-
- _name = pathstr;
- _path = keeppath;
- ret = true;
-
- } else {
-
- /* external files and/or very very old style sessions include full paths */
-
- _path = pathstr;
- _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
-
- if (access (_path.c_str(), R_OK) != 0) {
-
- /* file does not exist or we cannot read it */
-
- if (must_exist) {
- PBD::error << string_compose(_("Filesource: cannot find required file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- if (errno != ENOENT) {
- PBD::error << string_compose(_("Filesource: cannot check for existing file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- /* a new file */
-
- isnew = true;
- ret = true;
-
- } else {
-
- /* already exists */
-
- ret = true;
- }
- }
-
- out:
- return ret;
-}
-
-void
-SMFSource::set_search_path (string p)
-{
- _search_path = p;
-}
-
-
-void
-SMFSource::set_allow_remove_if_empty (bool yn)
-{
- if (writable()) {
- _allow_remove_if_empty = yn;
- }
-}
-
-int
-SMFSource::set_source_name (string newname, bool destructive)
-{
- //Glib::Mutex::Lock lm (_lock); FIXME
- string oldpath = _path;
- string newpath = Session::change_midi_path_by_name (oldpath, _name, newname, destructive);
-
- if (newpath.empty()) {
- PBD::error << string_compose (_("programming error: %1"), "cannot generate a changed midi path") << endmsg;
- return -1;
- }
-
- if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
- PBD::error << string_compose (_("cannot rename midi file for %1 to %2"), _name, newpath) << endmsg;
- return -1;
- }
-
- _name = Glib::path_get_basename (newpath);
- _path = newpath;
-
- return 0;
-}
-