comparison data/fileio/CSVFileWriter.cpp @ 1452:6e9615bde1f9 streaming-csv-writer

For sparse models, write whole model to CSV in one go
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 17 Apr 2018 10:37:50 +0100
parents a12fd0456f0c
children c546429d4c2f
comparison
equal deleted inserted replaced
1451:b40f67578976 1452:6e9615bde1f9
65 m_model->getStartFrame(), 65 m_model->getStartFrame(),
66 m_model->getEndFrame() 66 m_model->getEndFrame()
67 }; 67 };
68 MultiSelection selections; 68 MultiSelection selections;
69 selections.addSelection(all); 69 selections.addSelection(all);
70 writeSelection(&selections); 70 writeSelection(selections);
71 } 71 }
72 72
73 void 73 void
74 CSVFileWriter::writeSelection(MultiSelection *selection) 74 CSVFileWriter::writeSelection(MultiSelection selection)
75 { 75 {
76 try { 76 try {
77 TempWriteFile temp(m_path); 77 TempWriteFile temp(m_path);
78 78
79 QFile file(temp.getTemporaryFilename()); 79 QFile file(temp.getTemporaryFilename());
83 return; 83 return;
84 } 84 }
85 85
86 QTextStream out(&file); 86 QTextStream out(&file);
87 87
88 sv_frame_t blockSize = 65536;
89
90 if (m_model->isSparse()) {
91 // Write the whole in one go, as re-seeking for each block
92 // may be very costly otherwise
93 sv_frame_t startFrame, endFrame;
94 selection.getExtents(startFrame, endFrame);
95 blockSize = endFrame - startFrame;
96 }
97
88 bool completed = CSVStreamWriter::writeInChunks( 98 bool completed = CSVStreamWriter::writeInChunks(
89 out, 99 out,
90 *m_model, 100 *m_model,
91 *selection, 101 selection,
92 m_reporter, 102 m_reporter,
93 m_delimiter, 103 m_delimiter,
94 m_options 104 m_options,
105 blockSize
95 ); 106 );
96 107
97 file.close(); 108 file.close();
98 if (completed) { 109 if (completed) {
99 temp.moveToTarget(); 110 temp.moveToTarget();