| 1 |
/* CorpusEditor.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2026 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "CorpusEditor.h" |
| 20 |
#include "TextGridEditor.h" |
| 21 |
#include "praat.h" |
| 22 |
|
| 23 |
Thing_implement (CorpusEditor, TableEditor, 0); |
| 24 |
|
| 25 |
bool structCorpusEditor :: v_clickCell (integer row, integer column, bool shiftKeyPressed) { |
| 26 |
CorpusEditor_Parent :: v_clickCell (row, column, shiftKeyPressed); |
| 27 |
if (our selectedColumn == 3) { |
| 28 |
conststring32 rowTitle = Table_getStringValue_a (our table(), our selectedRow, our selectedColumn); |
| 29 |
structMelderFolder wavFolder { }; |
| 30 |
Melder_relativePathToFolder (our corpus -> folderWithSoundFiles.get(), & wavFolder); |
| 31 |
structMelderFolder compFolder { }; |
| 32 |
MelderFolder_getSubfolder (& wavFolder, Table_getStringValue_a (our table(), our selectedRow, 1), & compFolder); |
| 33 |
structMelderFolder regionFolder { }; |
| 34 |
MelderFolder_getSubfolder (& compFolder, Table_getStringValue_a (our table(), our selectedRow, 2), & regionFolder); |
| 35 |
structMelderFile soundFile { }; |
| 36 |
MelderFolder_getFile (& regionFolder, Table_getStringValue_a (our table(), our selectedRow, 3), & soundFile); |
| 37 |
|
| 38 |
our sound = Data_readFromFile (& soundFile).static_cast_move <structSound>(); |
| 39 |
Melder_require (our sound -> classInfo == classSound, |
| 40 |
U"File ", & soundFile, U" contains a ", Thing_className (our sound.get()), U" instead of a sound."); |
| 41 |
/* |
| 42 |
TODO: the following lines probably don't belong here. |
| 43 |
*/ |
| 44 |
int IOBJECT; |
| 45 |
WHERE (theCurrentPraatObjects -> list [IOBJECT]. object == our corpus) |
| 46 |
break; |
| 47 |
Melder_assert (IOBJECT > 0); |
| 48 |
Melder_assert (IOBJECT <= theCurrentPraatObjects -> n); |
| 49 |
autoTextGridEditor textgridEditor = TextGridEditor_create ( |
| 50 |
Melder_cat (ID_AND_FULL_NAME, U" – ", rowTitle), |
| 51 |
our corpus -> textGrids.at [our selectedRow], |
| 52 |
our sound.get(), |
| 53 |
nullptr, |
| 54 |
nullptr |
| 55 |
); |
| 56 |
praat_installEditor (textgridEditor.get(), IOBJECT); |
| 57 |
textgridEditor.releaseToUser(); |
| 58 |
} |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
autoCorpusEditor CorpusEditor_create (conststring32 title, Corpus corpus) { |
| 63 |
try { |
| 64 |
autoCorpusEditor me = Thing_new (CorpusEditor); |
| 65 |
TableEditor_init (me.get(), title, corpus -> recordings.get()); |
| 66 |
my corpus = corpus; |
| 67 |
return me; |
| 68 |
} catch (MelderError) { |
| 69 |
Melder_throw (U"CorpusEditor not created."); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/* End of file CorpusEditor.cpp */ |