comparison data/fileio/DataFileReaderFactory.cpp @ 392:183ee2a55fc7

* More work to abstract out interactive components used in the data library, so that it does not need to depend on QtGui.
author Chris Cannam
date Fri, 14 Mar 2008 17:14:21 +0000
parents 14e0f60435b8
children 59e7fe1b1003
comparison
equal deleted inserted replaced
391:5858cc462d0a 392:183ee2a55fc7
26 { 26 {
27 return "*.svl *.csv *.lab *.mid *.txt"; 27 return "*.svl *.csv *.lab *.mid *.txt";
28 } 28 }
29 29
30 DataFileReader * 30 DataFileReader *
31 DataFileReaderFactory::createReader(QString path, size_t mainModelSampleRate) 31 DataFileReaderFactory::createReader(QString path,
32 bool csv,
33 MIDIFileImportPreferenceAcquirer *acquirer,
34 CSVFormat format,
35 size_t mainModelSampleRate)
32 { 36 {
33 QString err; 37 QString err;
34 38
35 DataFileReader *reader = 0; 39 DataFileReader *reader = 0;
36 40
37 reader = new MIDIFileReader(path, mainModelSampleRate); 41 if (!csv) {
38 if (reader->isOK()) return reader; 42 reader = new MIDIFileReader(path, acquirer, mainModelSampleRate);
39 if (reader->getError() != "") err = reader->getError(); 43 if (reader->isOK()) return reader;
40 delete reader; 44 if (reader->getError() != "") err = reader->getError();
45 delete reader;
46 }
41 47
42 reader = new CSVFileReader(path, mainModelSampleRate); 48 if (csv) {
43 if (reader->isOK()) return reader; 49 reader = new CSVFileReader(path, format, mainModelSampleRate);
44 if (reader->getError() != "") err = reader->getError(); 50 if (reader->isOK()) return reader;
45 delete reader; 51 if (reader->getError() != "") err = reader->getError();
52 delete reader;
53 }
54
55 return 0;
56 }
57
58 DataFileReader *
59 DataFileReaderFactory::createReader(QString path,
60 MIDIFileImportPreferenceAcquirer *acquirer,
61 size_t mainModelSampleRate)
62 {
63 DataFileReader *reader = createReader
64 (path, false, acquirer, CSVFormat(), mainModelSampleRate);
65 if (reader) return reader;
66
67 reader = createReader
68 (path, true, acquirer, CSVFormat(path), mainModelSampleRate);
69 if (reader) return reader;
46 70
47 return 0; 71 return 0;
48 } 72 }
49 73
50 Model * 74 Model *
51 DataFileReaderFactory::load(QString path, size_t mainModelSampleRate) 75 DataFileReaderFactory::load(QString path,
76 MIDIFileImportPreferenceAcquirer *acquirer,
77 size_t mainModelSampleRate)
52 { 78 {
53 DataFileReader *reader = createReader(path, mainModelSampleRate); 79 DataFileReader *reader = createReader(path,
80 acquirer,
81 mainModelSampleRate);
54 if (!reader) return NULL; 82 if (!reader) return NULL;
55 83
56 try { 84 try {
57 Model *model = reader->load(); 85 Model *model = reader->load();
58 delete reader; 86 delete reader;
61 delete reader; 89 delete reader;
62 throw; 90 throw;
63 } 91 }
64 } 92 }
65 93
94 Model *
95 DataFileReaderFactory::loadNonCSV(QString path,
96 MIDIFileImportPreferenceAcquirer *acquirer,
97 size_t mainModelSampleRate)
98 {
99 DataFileReader *reader = createReader(path, false,
100 acquirer,
101 CSVFormat(),
102 mainModelSampleRate);
103 if (!reader) return NULL;
104
105 try {
106 Model *model = reader->load();
107 delete reader;
108 return model;
109 } catch (Exception) {
110 delete reader;
111 throw;
112 }
113 }
114
115 Model *
116 DataFileReaderFactory::loadCSV(QString path, CSVFormat format,
117 size_t mainModelSampleRate)
118 {
119 DataFileReader *reader = createReader(path, true, 0, format,
120 mainModelSampleRate);
121 if (!reader) return NULL;
122
123 try {
124 Model *model = reader->load();
125 delete reader;
126 return model;
127 } catch (Exception) {
128 delete reader;
129 throw;
130 }
131 }
132