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#ifndef __AUDIO_SUPPORTED_FILE_H__
5#define __AUDIO_SUPPORTED_FILE_H__
6
7#include <memory>
8
9#include "utils/utf8_string.h"
10
16
17#define SUPPORTED_FILE_DND_PREFIX Z_DND_STRING_PREFIX "FileDescriptor::"
18
22enum class FileType
23{
24 Midi,
25 Mp3,
26 Flac,
27 Ogg,
28 Wav,
29 Directory,
32 Other,
33 NumFileTypes,
34};
35
39class FileDescriptor
40{
41public:
42 FileDescriptor () = default;
43
44 FileDescriptor (const fs::path &abs_path);
45
53 static std::unique_ptr<FileDescriptor>
54 new_from_uri (const utils::Utf8String &uri);
55
61 static utils::Utf8String get_type_description (FileType type);
62
66 static bool is_type_supported (FileType type);
67
71 static bool is_type_audio (FileType type);
72
76 static bool is_type_midi (FileType type);
77
81 static std::optional<utils::Utf8String> get_type_ext (FileType type);
82
86 static FileType get_type_from_path (const fs::path &file);
87
88 bool is_audio () const { return is_type_audio (type_); }
89
90 bool is_midi () const { return is_type_midi (type_); }
91
92 bool is_supported () const { return is_type_supported (type_); }
93
94 auto get_label () const { return label_; }
95
99 bool should_autoplay () const;
100
104 utils::Utf8String get_icon_name () const;
105
109 utils::Utf8String get_info_text_for_label () const;
110
111public:
113 fs::path abs_path_;
114
117
119 utils::Utf8String label_;
120
122 bool hidden_ = false;
123};
124
128
129#endif
utils::Utf8String get_info_text_for_label() const
Returns a pango markup to be used in GTK labels.
static bool is_type_midi(FileType type)
Returns if the FileDescriptor is a midi file.
static std::optional< utils::Utf8String > get_type_ext(FileType type)
Returns the most common extension for the given filetype.
utils::Utf8String get_icon_name() const
Gets the corresponding icon name for the given FileDescriptor's type.
fs::path abs_path_
Absolute path.
bool should_autoplay() const
Returns whether the given file should auto-play (shorter than 1 min).
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.
FileType type_
Type of file.
static utils::Utf8String get_type_description(FileType type)
Returns a human readable description of the given file type.
static bool is_type_audio(FileType type)
Returns if the FileDescriptor is an audio file.
bool hidden_
Hidden or not.
static bool is_type_supported(FileType type)
Returns if the given type is supported.
static FileType get_type_from_path(const fs::path &file)
Returns the file type of the given file path.
FileType
File type.
@ ParentDirectory
Special entry ".." for the parent dir.