Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
file_descriptor.h
1// SPDX-FileCopyrightText: © 2019-2021, 2023-2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <memory>
7
8#include "utils/utf8_string.h"
9
10namespace zrythm::legacy
11{
12
18
19#define SUPPORTED_FILE_DND_PREFIX Z_DND_STRING_PREFIX "FileDescriptor::"
20
24enum class FileType
25{
26 Midi,
27 Mp3,
28 Flac,
29 Ogg,
30 Wav,
31 Directory,
34 Other,
35 NumFileTypes,
36};
37
41class FileDescriptor
42{
43public:
44 FileDescriptor () = default;
45
46 FileDescriptor (const std::filesystem::path &abs_path);
47
55 static std::unique_ptr<FileDescriptor>
57
64
68 static bool is_type_supported (FileType type);
69
73 static bool is_type_audio (FileType type);
74
78 static bool is_type_midi (FileType type);
79
83 static std::optional<utils::Utf8String> get_type_ext (FileType type);
84
88 static FileType get_type_from_path (const std::filesystem::path &file);
89
90 bool is_audio () const { return is_type_audio (type_); }
91
92 bool is_midi () const { return is_type_midi (type_); }
93
94 bool is_supported () const { return is_type_supported (type_); }
95
96 auto get_label () const { return label_; }
97
101 bool should_autoplay () const;
102
107
112
113public:
115 std::filesystem::path abs_path_;
116
119
122
124 bool hidden_ = false;
125};
126
130
131}
utils::Utf8String get_icon_name() const
Gets the corresponding icon name for the given FileDescriptor's type.
static utils::Utf8String get_type_description(FileType type)
Returns a human readable description of the given file type.
static bool is_type_midi(FileType type)
Returns if the FileDescriptor is a midi file.
static bool is_type_supported(FileType type)
Returns if the given type is supported.
static std::unique_ptr< FileDescriptor > new_from_uri(const utils::Utf8String &uri)
Creates a new FileDescriptor from a URI.
utils::Utf8String label_
Human readable label.
std::filesystem::path abs_path_
Absolute path.
static std::optional< utils::Utf8String > get_type_ext(FileType type)
Returns the most common extension for the given filetype.
utils::Utf8String get_info_text_for_label() const
Returns a pango markup to be used in GTK labels.
static bool is_type_audio(FileType type)
Returns if the FileDescriptor is an audio file.
static FileType get_type_from_path(const std::filesystem::path &file)
Returns the file type of the given file path.
bool should_autoplay() const
Returns whether the given file should auto-play (shorter than 1 min).
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:37
@ ParentDirectory
Special entry ".." for the parent dir.