Skip to content

Commit

Permalink
Added Save/Annotations as JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Sep 23, 2024
1 parent 0b0503b commit 95d9a7f
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ v1.2.9
- Handle **AV_DISPOSITION_ATTACHED_PIC** properly, instead of skipping it.
- Added PNG decoder so attached png pictures in .wav files are decoded
properly.
- Added a File->Save Annotations as JSON. This allows you to export the
annotations as a .json file.

v1.2.8
======
Expand Down
2 changes: 2 additions & 0 deletions src/lib/mrvCore/mrvHotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace mrv
Hotkey kSaveImage(false, false, false, false, 0);
Hotkey kSaveImageToFolder(false, false, false, false, 0);
Hotkey kSaveSequence(true, false, false, true, 's');
Hotkey kSaveAnnotationsAsJson(false, false, false, false, 0);
Hotkey kSaveOTIOEDL(false, false, false, false, 0);
Hotkey kSavePDF(false, false, false, false, 0);
Hotkey kSaveSession(true, false, false, false, 's');
Expand Down Expand Up @@ -368,6 +369,7 @@ namespace mrv

HotkeyEntry(_("Save Movie or Sequence"), &kSaveSequence),
HotkeyEntry(_("Save OTIO Timeline"), &kSaveOTIOEDL),
HotkeyEntry(_("Save Annotations as JSON"), &kSaveAnnotationsAsJson),
HotkeyEntry(_("Save PDF Document"), &kSavePDF),
HotkeyEntry(_("Save Session"), &kSaveSession),
HotkeyEntry(_("Save Session As"), &kSaveSessionAs),
Expand Down
1 change: 1 addition & 0 deletions src/lib/mrvCore/mrvHotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace mrv
extern Hotkey kSaveImageToFolder;
extern Hotkey kSaveOTIOEDL;
extern Hotkey kSaveSequence;
extern Hotkey kSaveAnnotationsAsJson;
extern Hotkey kSavePDF;
extern Hotkey kSaveSession;
extern Hotkey kSaveSessionAs;
Expand Down
27 changes: 27 additions & 0 deletions src/lib/mrvFl/mrvCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,33 @@ namespace mrv
#endif
}

void save_annotations_as_json_cb(Fl_Menu_* w, ViewerUI* ui)
{
auto player = ui->uiView->getTimelinePlayer();
if (!player)
return;

const auto& annotations = player->getAllAnnotations();
if (annotations.empty())
return;

const std::string& file = save_annotations();
if (file.empty())
return;

Message j;
std::vector< draw::Annotation > flatAnnotations;
for (const auto& annotation : annotations)
{
flatAnnotations.push_back(*annotation.get());
}
j["annotations"] = flatAnnotations;

std::ofstream f(file);
f << j;
}


void close_current_cb(Fl_Widget* w, ViewerUI* ui)
{
// Must come before model->close().
Expand Down
1 change: 1 addition & 0 deletions src/lib/mrvFl/mrvCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace mrv

void save_single_frame_to_folder_cb(Fl_Menu_* w, ViewerUI* ui);
void save_single_frame_cb(Fl_Menu_* w, ViewerUI* ui);
void save_annotations_as_json_cb(Fl_Menu_* w, ViewerUI* ui);
void save_movie_cb(Fl_Menu_* w, ViewerUI* ui);
void save_pdf_cb(Fl_Menu_* w, ViewerUI* ui);

Expand Down
24 changes: 24 additions & 0 deletions src/lib/mrvFl/mrvFileRequester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,30 @@ namespace mrv
return file;
}

std::string save_annotations(const char* startdir)
{
const std::string kJSON_PATTERN = _("Annotations (*.{json})");
const std::string kALL_PATTERN = kJSON_PATTERN;

std::string title = _("Save Annotations to JSON");

if (!startdir)
startdir = "";

std::string file = file_save_single_requester(
title.c_str(), kALL_PATTERN.c_str(), startdir, true);

if (file.empty())
return file;

if (file.substr(file.size() - 5, file.size()) != ".json")
{
file += ".json";
}

return file;
}

std::string save_pdf(const char* startdir)
{
const std::string kPDF_PATTERN = _("Acrobat PDF (*.{pdf})");
Expand Down
2 changes: 2 additions & 0 deletions src/lib/mrvFl/mrvFileRequester.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace mrv

std::string save_movie_or_sequence_file(const char* startfile = nullptr);

std::string save_annotations(const char* startdir = nullptr);

std::string save_pdf(const char* startdir = nullptr);

std::string open_session_file(const char* startfile = nullptr);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/mrvGL/mrvTimelineViewportEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ namespace mrv
std::shared_ptr< draw::Shape > s;
if (annotation)
s = annotation->lastShape();

p.lastEvent = 0;

if (!s->laser)
Expand All @@ -1070,6 +1070,7 @@ namespace mrv
kLaserFadeTimeout, (Fl_Timeout_Handler)laserFade_cb,
laserData);
}
p.ui->uiMain->fill_menu(p.ui->uiMenuBar);
_updateCursor();
return 1;
}
Expand Down
16 changes: 13 additions & 3 deletions src/lib/mrvUI/mrvMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ namespace mrv
menu->add(
_("File/Save/OTIO EDL Timeline"), kSaveOTIOEDL.hotkey(),
(Fl_Callback*)save_timeline_to_disk_cb, ui, mode | FL_MENU_DIVIDER);

auto player = ui->uiView->getTimelinePlayer();
mode = 0;
if (!player || !player->hasAnnotations())
mode = FL_MENU_INACTIVE;

menu->add(
_("File/Save/Annotations as JSON"), kSaveAnnotationsAsJson.hotkey(),
(Fl_Callback*)save_annotations_as_json_cb, ui, mode | FL_MENU_DIVIDER);

mode = 0;
if (numFiles == 0)
mode = FL_MENU_INACTIVE;
menu->add(
_("File/Save/PDF Document"), kSavePDF.hotkey(),
(Fl_Callback*)save_pdf_cb, ui, FL_MENU_DIVIDER | mode);
Expand Down Expand Up @@ -789,9 +802,6 @@ namespace mrv
}

timeline::Playback playback = timeline::Playback::Stop;
auto player = uiView->getTimelinePlayer();
if (player)
playback = player->playback();

mode = FL_MENU_RADIO;
if (numFiles == 0)
Expand Down

0 comments on commit 95d9a7f

Please sign in to comment.