Apply MIDI looping patch from torbenh, with minor changes.
[ardour.git] / libs / ardour / tape_file_matcher.cc
1 /*
2         Copyright (C) 2007 Tim Mayberry 
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <pbd/error.h>
20
21 #include <ardour/tape_file_matcher.h>
22
23 #include "i18n.h"
24
25 namespace {
26
27 const char* const tape_file_regex_string = X_("/T[0-9][0-9][0-9][0-9]-");
28
29 }
30
31 namespace ARDOUR {
32
33 TapeFileMatcher::TapeFileMatcher()
34 {
35         int err;
36
37         if ((err = regcomp (&m_compiled_pattern,
38                                         tape_file_regex_string, REG_EXTENDED|REG_NOSUB)))
39         {
40                 char msg[256];
41                 
42                 regerror (err, &m_compiled_pattern, msg, sizeof (msg));
43                 
44                 PBD::error << string_compose (_("Cannot compile tape track regexp for use (%1)"), msg) << endmsg;
45                 // throw
46         }
47
48 }
49
50 bool
51 TapeFileMatcher::matches (const string& audio_filename) const
52 {
53
54         if (regexec (&m_compiled_pattern, audio_filename.c_str(), 0, 0, 0) == 0)
55         {
56                 // matches
57                 return true;
58         }
59         return false;
60 }
61
62 } // namespace ARDOUR