Skip to content

openFrameworks addon for notifying changes to files or directories.

License

Notifications You must be signed in to change notification settings

UltraCombos/ofxWatcher

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ofxWatcher

Notify when changes are made to a file or directory.

usage

ofxWatchPath(path, callback, [option], [retain])
ofxWatchPath(path, loader, callback, [option], [retain])

path

A path is specified as a relative or absolute path from the data folder.
It can be a file or a directory or a path with wildcards.
A wildcard is *(matches to any string) or **(matches to any directory recursively).
If the path is for a directory, it watches all of the children.

(Example)
If there are these files...

  1. "videos/highQ/recorded.mov"
  2. "videos/highQ/recorded.mp4"
  3. "videos/lowQ/half.mov"
  4. "videos/lowQ/sequence.mov"
  5. "settings/playback/sequence.json"
  • "videos/*/*.mov" matches to 1,3,4
  • "**/highQ" matches to 1,2
  • "**/sequence*" matches to 4,5
  • "**" matches to 1,2,3,4,5

callback

When changes are made to a file or directory while watching, the callback is called.
Callback functions can take the following 4 forms.
You can use function pointer or lambda as well.

  1. callback(void)
  2. callback(const std::filesystem::path&)
  3. callback(const MediumType&)
  4. callback(const MediumType&, const std::filesystem::path&)

MediumType is a product of loader function.

loader

Loader function modifies a path into any types.
It is mainly intended to be used for loading the file.

(Example)

ofxWatchPath("settings/*.json", ofLoadJson, [](const ofJson &json) {
	std::cout << json.dump(2) << std::endl;
});

Tips
If you want to use an existing function that expects arguments other than filepath or a member function, consider using std::bind.

option

ofxWatcherOption option;
option.check_interval = 10;
option.file_type_flag = ofx::watcher::REGULAR | ofx::watcher::DIRECTORY;
option.absolute_path = true;
option.finder_option.excludes = {".DS_Store",".git"};
option.finder_option.allow_ext = {".png",".jpg"};

float check_interval

Check for modifies at this interval in seconds.
default: 1

std::size_t file_type_flag

Only checks files or directories of this type.
See FileTypeFlag in ofxWatcher.h
default: REGULAR

bool absolute_path

If true, callback or loader is called with absolute path.
default: false

std::vectorstd::string excludes

Excludes files or directories that has a name in this vector.
An exact match is required.
default: [".DS_Store"]

std::vectorstd::string allow_ext

If specified, files with unspecified extensions are ignored.
Each ext should start with ..
default: (empty)

bool retain

If true, ofxWatcher keeps the shared_ptr created by ofxWatchPath.
If you want to control the object's lifecycle, call ofxWatchPath with retain=false.
default: true

About

openFrameworks addon for notifying changes to files or directories.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.9%
  • Makefile 0.1%