comparison data/fileio/DataFileReaderFactory.cpp @ 1491:1dc64d3d323c import-audio-data

Support progress reporter for data file loads
author Chris Cannam
date Fri, 29 Jun 2018 13:44:53 +0100
parents 26cf6d5251ec
children 70e172e6cc59
comparison
equal deleted inserted replaced
1490:9ab8e5ec4731 1491:1dc64d3d323c
30 DataFileReader * 30 DataFileReader *
31 DataFileReaderFactory::createReader(QString path, 31 DataFileReaderFactory::createReader(QString path,
32 bool csv, 32 bool csv,
33 MIDIFileImportPreferenceAcquirer *acquirer, 33 MIDIFileImportPreferenceAcquirer *acquirer,
34 CSVFormat format, 34 CSVFormat format,
35 sv_samplerate_t mainModelSampleRate) 35 sv_samplerate_t mainModelSampleRate,
36 ProgressReporter *reporter)
36 { 37 {
37 QString err; 38 QString err;
38 39
39 DataFileReader *reader = 0; 40 DataFileReader *reader = 0;
40 41
41 if (!csv) { 42 if (!csv) {
42 reader = new MIDIFileReader(path, acquirer, mainModelSampleRate); 43 reader = new MIDIFileReader(path,
44 acquirer,
45 mainModelSampleRate,
46 reporter);
43 if (reader->isOK()) return reader; 47 if (reader->isOK()) return reader;
44 if (reader->getError() != "") err = reader->getError(); 48 if (reader->getError() != "") err = reader->getError();
45 delete reader; 49 delete reader;
46 } 50 }
47 51
48 if (csv) { 52 if (csv) {
49 reader = new CSVFileReader(path, format, mainModelSampleRate); 53 reader = new CSVFileReader(path,
54 format,
55 mainModelSampleRate,
56 reporter);
50 if (reader->isOK()) return reader; 57 if (reader->isOK()) return reader;
51 if (reader->getError() != "") err = reader->getError(); 58 if (reader->getError() != "") err = reader->getError();
52 delete reader; 59 delete reader;
53 } 60 }
54 61
56 } 63 }
57 64
58 DataFileReader * 65 DataFileReader *
59 DataFileReaderFactory::createReader(QString path, 66 DataFileReaderFactory::createReader(QString path,
60 MIDIFileImportPreferenceAcquirer *acquirer, 67 MIDIFileImportPreferenceAcquirer *acquirer,
61 sv_samplerate_t mainModelSampleRate) 68 sv_samplerate_t mainModelSampleRate,
69 ProgressReporter *reporter)
62 { 70 {
63 DataFileReader *reader = createReader 71 DataFileReader *reader = createReader
64 (path, false, acquirer, CSVFormat(), mainModelSampleRate); 72 (path, false, acquirer, CSVFormat(), mainModelSampleRate, reporter);
65 if (reader) return reader; 73 if (reader) return reader;
66 74
67 reader = createReader 75 reader = createReader
68 (path, true, acquirer, CSVFormat(path), mainModelSampleRate); 76 (path, true, acquirer, CSVFormat(path), mainModelSampleRate, reporter);
69 if (reader) return reader; 77 if (reader) return reader;
70 78
71 return 0; 79 return 0;
72 } 80 }
73 81
74 Model * 82 Model *
75 DataFileReaderFactory::load(QString path, 83 DataFileReaderFactory::load(QString path,
76 MIDIFileImportPreferenceAcquirer *acquirer, 84 MIDIFileImportPreferenceAcquirer *acquirer,
77 sv_samplerate_t mainModelSampleRate) 85 sv_samplerate_t mainModelSampleRate,
86 ProgressReporter *reporter)
78 { 87 {
79 DataFileReader *reader = createReader(path, 88 DataFileReader *reader = createReader(path,
80 acquirer, 89 acquirer,
81 mainModelSampleRate); 90 mainModelSampleRate,
91 reporter);
82 if (!reader) return NULL; 92 if (!reader) return NULL;
83 93
84 try { 94 try {
85 Model *model = reader->load(); 95 Model *model = reader->load();
86 delete reader; 96 delete reader;
92 } 102 }
93 103
94 Model * 104 Model *
95 DataFileReaderFactory::loadNonCSV(QString path, 105 DataFileReaderFactory::loadNonCSV(QString path,
96 MIDIFileImportPreferenceAcquirer *acquirer, 106 MIDIFileImportPreferenceAcquirer *acquirer,
97 sv_samplerate_t mainModelSampleRate) 107 sv_samplerate_t mainModelSampleRate,
108 ProgressReporter *reporter)
98 { 109 {
99 DataFileReader *reader = createReader(path, false, 110 DataFileReader *reader = createReader(path, false,
100 acquirer, 111 acquirer,
101 CSVFormat(), 112 CSVFormat(),
102 mainModelSampleRate); 113 mainModelSampleRate,
114 reporter);
103 if (!reader) return NULL; 115 if (!reader) return NULL;
104 116
105 try { 117 try {
106 Model *model = reader->load(); 118 Model *model = reader->load();
107 delete reader; 119 delete reader;
112 } 124 }
113 } 125 }
114 126
115 Model * 127 Model *
116 DataFileReaderFactory::loadCSV(QString path, CSVFormat format, 128 DataFileReaderFactory::loadCSV(QString path, CSVFormat format,
117 sv_samplerate_t mainModelSampleRate) 129 sv_samplerate_t mainModelSampleRate,
130 ProgressReporter *reporter)
118 { 131 {
119 DataFileReader *reader = createReader(path, true, 0, format, 132 DataFileReader *reader = createReader(path, true, 0, format,
120 mainModelSampleRate); 133 mainModelSampleRate,
134 reporter);
121 if (!reader) return NULL; 135 if (!reader) return NULL;
122 136
123 try { 137 try {
124 Model *model = reader->load(); 138 Model *model = reader->load();
125 delete reader; 139 delete reader;