Various changes

This commit is contained in:
Zachary Hall 2024-03-26 18:39:02 -07:00
parent 81d85a1476
commit 57cb111358
39 changed files with 1657 additions and 390 deletions

12
BUILDING.md Normal file
View file

@ -0,0 +1,12 @@
# Building Looper
This project uses CMake for its build system, and it is recommended to build the software in a different directory than the source code.
## Build options
Options include:
|-------------|-------------------------------------------------------------|
|Option |Result |
|-------------|-------------------------------------------------------------|
|USE_VGMSTREAM|Enables the linking of VGMSteam. |
|USE_PORTALS |Enables the use of libportal in frontends that support it. |
|DISABLE_*_UI |Disables the respective UI specified by the option. |
|USE_GLES |Enables using OpenGL ES vs OpenGL in the Dear ImGui frontend.|

View file

@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.28)
project(looper VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SDL_MIXER_X_STATIC ON CACHE BSDL_MIXER_X_SHARED OFF CACHE BOOL "")
set(SDL_MIXER_X_STATIC ON CACHE BOOL "")
set(SDL_MIXER_X_SHARED OFF CACHE BOOL "")
set(DOWNLOAD_AUDIO_CODECS_DEPENDENCY ON CACHE BOOL "")
set(AUDIO_CODECS_BUILD_LOCAL_SDL2 OFF CACHE BOOL "" FORCE)
set(MIXERX_LGPL ON CACHE BOOL "" FORCE)
set(USE_MIDI ON CACHE BOOL "" FORCE)
set(USE_MIDI_NATIVE_ALT OFF CACHE BOOL "" FORCE)
@ -51,7 +54,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(log)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/meson2cmake_cfg.py ${CMAKE_CURRENT_SOURCE_DIR}/config.meson.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in)
#execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/meson2cmake_cfg.py ${CMAKE_CURRENT_SOURCE_DIR}/config.meson.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.h.in)
set(DEBUG_MODE_VALUE ${DEBUG})
configure_file(config.cmake.h.in config.h)
macro(target_pkgconfig)
@ -135,9 +139,6 @@ execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen_ui_backend_inc.py ${ENAB
prefix_all(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ backend_glue.cpp main.cpp)
add_executable(looper ${SOURCES})
add_dependencies(looper looper_assets ${UI_BACKENDS})
if(${USE_GLES})
target_compile_definitions(looper PRIVATE "IMGUI_IMPL_OPENGL_ES2")
endif()
find_program(ASCLI_EXE NAMES "appstreamcli" NO_CACHE)
if(${ASCLI_EXE} STREQUAL "ASCLIEXE-NOTFOUND")
message("Cannot verify Appstream Metadata.")

4
COPYING.md Normal file
View file

@ -0,0 +1,4 @@
# Dual License
This software is dual-licensed under either the [MIT](LICENSE.MIT) or [GPL 3.0 or later](LICENSE.GPL), at your option, as far as is legally possible.
## Warning
Note that some build configurations of the dependencies will cause them to include software licensed under the GPL, and you will not be able to use the binaries under the terms of the MIT license, due to the terms of the GPL.

674
LICENSE.GPL Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

7
assets/gtk-frontend.css Normal file
View file

@ -0,0 +1,7 @@
button {
-gtk-icon-style: symbolic;
}
#controls-box {
margin: 0;
padding: 0;
}

View file

@ -1,14 +1,13 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
Copyright (C) 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
@ -17,109 +16,97 @@ freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
former contains code derived from the library, while the latter only
works together with the library.
GNU LESSER GENERAL PUBLIC LICENSE
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
@ -158,7 +145,7 @@ Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
@ -216,7 +203,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
@ -267,8 +254,8 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
@ -295,31 +282,23 @@ of these things:
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
@ -329,7 +308,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
@ -368,9 +347,9 @@ Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
@ -411,7 +390,7 @@ excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
@ -422,7 +401,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
@ -456,3 +435,47 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View file

@ -3,7 +3,7 @@
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@ -493,8 +493,7 @@ does.>
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper
mail.

View file

@ -40,6 +40,10 @@ def add_license(input: str, output: str):
def compile_program(file: str, output: str):
print("Compiling file '%s' to '%s'" % (path.abspath(file), path.abspath(output)))
subprocess.call([os.environ.get("CXX", "c++"), file, "-o", output])
def add_css(file: str, output: str):
CSS_FILE = output + ".h"
print("Adding CSS file '%s' (C identifier '%s') from file '%s'" % (file, output, CSS_FILE))
add_basic(file, output)
compile_program("../backends/ui/imgui/imgui/misc/fonts/binary_to_compressed_c.cpp", "btcc")
for i in glob("Noto_Sans/*.ttf"):
add_font(i)
@ -49,19 +53,22 @@ add_font("forkawesome-webfont.ttf", "forkawesome")
add_graphic("icon.png")
add_license("Noto_Sans/OFL.txt", "notosans")
add_license("Noto_Sans_JP/OFL.txt", "notosansjp")
add_license("../LICENSE", "looper")
add_license("../LICENSE.MIT", "looper_mit")
add_license("../LICENSE.GPL", "looper_gpl")
add_license("../COPYING.md", "looper")
add_license("../subprojects/jsoncpp/LICENSE", "jsoncpp")
add_license("../subprojects/SDL-Mixer-X/COPYING.txt", "sdl_mixer_x")
add_license("../backends/ui/imgui/imgui-filebrowser/LICENSE", "imgui_filebrowser")
add_license("../backends/ui/imgui/imgui/LICENSE.txt", "imgui")
add_license("licenses/SoundTouch.txt", "soundtouch")
add_license("licenses/libportal.txt", "libportal")
add_license("licenses/lgpl-3.0.txt", "lgpl_3_0")
add_license("licenses/lgpl-2.1.txt", "lgpl_2_1")
add_license("licenses/lgpl-2.0.txt", "lgpl_2_0")
add_license("licenses/ForkAwesome.txt", "forkawesome")
add_license("licenses/libintl.txt", "libintl")
add_license("licenses/cli11.txt", "cli11")
add_license("licenses/TomlPlusPlus.txt", "tomlplusplus")
add_license("../backends/ui/imgui/IconFontCppHeaders/licence.txt", "icnfntcpphdrs")
add_css("gtk-frontend.css", "gtk_frontend_css")
def finalize(output: str, ASSETS = ASSETS):
print("Writing a header including all previous asset headers and writing it to '%s'..." % output)
with open(output, "wt+") as f:

View file

@ -13,10 +13,9 @@ int UIBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
g_set_application_name("Looper")
#endif
args = realArgs;
playback = new Playback();
playback = new PlaybackInstance();
CLI::App app{DESCRIPTION};
std::string filename = "";
DBusAPISender sender;
app.allow_extras();
double new_speed = 1.0;
double new_tempo = 1.0;
@ -24,15 +23,19 @@ int UIBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
auto speed_opt = app.add_option("-s,--speed", new_speed, "Set the initial speed of the playback.")->default_val(1.0);
auto tempo_opt = app.add_option("-t,--tempo", new_tempo, "Set the initial tempo of the playback.")->default_val(1.0);
auto pitch_opt = app.add_option("-p,--pitch", new_pitch, "Set the initial pitch of the playback.")->default_val(1.0);
bool multi_instance = false;
auto multi_instance_opt = app.add_flag<bool>("-m,--multi-instance", multi_instance, "Disables the DBus api to allow multiple instances.");
try {
app.parse(args);
} catch (const CLI::ParseError &e) {
throw app.exit(e);
}
playback->speed = new_speed;
playback->tempo = new_tempo;
playback->pitch = new_pitch;
playback->SetSpeed(new_speed);
playback->SetTempo(new_tempo);
playback->SetPitch(new_pitch);
args = app.remaining();
if (!multi_instance) {
DBusAPISender sender;
if (!sender.isOnlyInstance()) {
if (args.size() > 0) {
sender.playFile(args[0]);
@ -50,6 +53,9 @@ int UIBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
} else {
dbus_api = new DBusAPI(playback);
}
} else {
dbus_api = nullptr;
}
if (args.size() > 0) {
playback->Start(args[0]);
}
@ -61,6 +67,10 @@ void UIBackend::deinit_backends() {
}
backends.clear();
}
UIBackend::~UIBackend() {
if (dbus_api != nullptr) delete dbus_api;
delete playback;
}
std::string UIBackend::get_name() {
return "Unknown frontend";
}

View file

@ -14,6 +14,9 @@ class UIBackend {
virtual std::string get_id();
virtual std::string get_name();
UIBackend() = default;
virtual void add_licenses() {
// Don't add any here, but leave this specified. That way, licenses specific to UI frontends are only added per UI frontend.
}
virtual int run(std::vector<std::string> realArgs, int argc, char **argv);
static std::map<std::string, UIBackend*> backends;
static inline std::optional<UIBackend*> get_backend(std::string id) {
@ -40,5 +43,6 @@ class UIBackend {
backends[backend_id] = backend;
}
static void deinit_backends();
virtual ~UIBackend();
};
void init_backends();

View file

@ -1,4 +1,4 @@
set(BACKEND_GTK_SRC_BASE main.cpp main_window.cpp my_slider.cpp options_window.cpp)
set(BACKEND_GTK_SRC_BASE main.cpp main_window.cpp my_slider.cpp options_window.cpp theme.cpp about_window.cpp)
set(BACKEND_GTK_SRC )
foreach(SRC IN ITEMS ${BACKEND_GTK_SRC_BASE})
set(BACKEND_GTK_SRC ${BACKEND_GTK_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})

View file

@ -0,0 +1,18 @@
#include "about_window.hpp"
#include <license.hpp>
#include <config.h>
AboutWindow::AboutWindow() {
set_authors({"Catmeow72"});
set_version(TAG);
Glib::ustring license_text;
auto &licenses = get_license_data();
for (auto &license : licenses) {
license_text += license.Project + ": " + license.Spdx + "\n";
license_text += license.LicenseContents;
license_text += "\n\n";
}
set_license(license_text);
set_wrap_license(true);
set_logo_icon_name("looper");
}

View file

@ -0,0 +1,11 @@
#pragma once
#include <gtkmm.h>
#include <any>
#include <typeindex>
#include <set>
#include <options.hpp>
#include <license.hpp>
class AboutWindow : public Gtk::AboutDialog {
public:
AboutWindow();
};

View file

@ -1,5 +1,7 @@
#include "main.h"
#include "main_window.hpp"
#include <assets/assets.h>
#include <license.hpp>
std::string GtkBackend::get_id() {
return "gtk";
}
@ -11,11 +13,41 @@ int GtkBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
if (ret != 0) {
return ret;
}
auto app = Gtk::Application::create("com.experimentalcraft.Looper");
auto *win = new MainWindow(playback);
app->signal_startup().connect([=]() {
app->add_window(*win);
win->set_visible();
Glib::set_application_name("Looper");
auto app = Gtk::Application::create("com.experimentalcraft.Looper.GTK", Gio::Application::Flags::NON_UNIQUE);
char *gtk_frontend_css = (char*)malloc(gtk_frontend_css_size + 1);
memcpy(gtk_frontend_css, gtk_frontend_css_data, gtk_frontend_css_size);
gtk_frontend_css[gtk_frontend_css_size] = '\0';
std::string gtk_frontend_css_str = std::string(gtk_frontend_css);
free(gtk_frontend_css);
auto provider = Gtk::CssProvider::create();
provider->load_from_string(gtk_frontend_css_str);
app->signal_startup().connect([=,this]() {
app->add_action("quit", [app]() {
app->quit();
});
return app->run(argc, argv);
Gtk::StyleContext::add_provider_for_display(Gdk::Display::get_default(), provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
});
app->signal_activate().connect([=,this] {
auto *win = new MainWindow(playback, app);
win->present();
});
ret = app->run(argc, argv);
return ret;
}
void GtkBackend::add_licenses() {
auto &license_data = get_license_data();
auto gtkmm = LicenseData("GtkMM", "lgpl-2.1");
auto glibmm = LicenseData("GlibMM", "lgpl-2.1");
auto glib = LicenseData("Glib", "lgpl-2.1-or-later");
auto gtk = LicenseData("GTK", "lgpl-2.0");
LOAD_LICENSE(gtkmm, lgpl_2_1);
LOAD_LICENSE(glibmm, lgpl_2_1);
LOAD_LICENSE(glib, lgpl_2_1);
LOAD_LICENSE(gtk, lgpl_2_0);
license_data.insert(gtkmm);
license_data.insert(glibmm);
license_data.insert(glib);
license_data.insert(gtk);
}

View file

@ -2,9 +2,11 @@
#include <backend.hpp>
#include <string>
#include <vector>
#define GTK_FRONTEND
class GtkBackend : public UIBackend {
public:
std::string get_id() override;
std::string get_name() override;
void add_licenses() override;
int run(std::vector<std::string> realArgs, int argc, char **argv) override;
};

View file

@ -2,6 +2,7 @@
#include <gtkmm.h>
#include "my_slider.hpp"
#include <filesystem>
#include <gtkmm/menubutton.h>
#include <util.hpp>
void MainWindow::set_song_loaded(bool loaded) {
bool unloaded = !loaded;
@ -9,6 +10,18 @@ void MainWindow::set_song_loaded(bool loaded) {
pause_btn.set_sensitive(loaded);
restart_btn.set_sensitive(loaded);
stop_btn.set_sensitive(loaded);
action_enabled_changed("toggle_pause", loaded);
action_enabled_changed("stop_playback", loaded);
action_enabled_changed("restart_playback", loaded);
}
void MainWindow::set_subtitle(std::optional<Glib::ustring> subtitle) {
subTitleLabel.set_visible(subtitle.has_value());
if (subtitle.has_value()) {
subTitleLabel.set_text(subtitle.value());
set_title(subtitle.value() + Glib::ustring(" - ") + titleLabel.get_text());
} else {
set_title(titleLabel.get_text());
}
}
void MainWindow::update_file(optional<std::string> new_file) {
@ -19,18 +32,22 @@ void MainWindow::update_file(optional<std::string> new_file) {
length = playback->GetLength();
length_component_count = TimeToComponentCount(length);
length_label.set_text(TimeToString(length, length_component_count).c_str());
std::filesystem::path file_path(new_file.value());
song_name = file_path.stem().string();
set_title((song_name + std::string(" - Looper")).c_str());
seek_bar.set_range(0, length);
} else {
length = 0;
length_component_count = 2;
length_label.set_text("00:00");
song_name = "";
set_title("Looper");
seek_bar.set_value(0.0);
}
std::optional<std::string> title = playback->get_current_title();
song_name = title.value_or("");
subTitleLabel.set_visible(title.has_value());
if (title.has_value()) {
set_subtitle(song_name);
} else {
set_subtitle({});
}
bool length_valid = length > 0;
seek_bar.set_visible(length_valid);
seek_indeterminate.set_visible(!length_valid);
@ -103,15 +120,27 @@ bool MainWindow::update() {
seek_bar.set_value(position);
}
time_label.set_text(TimeToString(position, length_component_count));
pause_btn.set_icon_name(playback->IsPaused() ? "media-playback-start-symbolic" : "media-playback-pause-symbolic");
std::vector<Glib::ustring> classes;
if (playback->IsPaused()) {
classes.push_back("paused");
pause_btn.set_icon_name("media-playback-start");
} else {
pause_btn.set_icon_name("media-playback-pause");
}
if (length <= 0) {
classes.push_back("no-length");
}
if (playback_file.has_value()) {
classes.push_back("loaded");
}
if (signals_handleable.signal_unexpected(PlaybackSignalPitchChanged)) {
pitch_slider.set_value(playback->pitch);
pitch_slider.set_value(playback->GetPitch());
}
if (signals_handleable.signal_unexpected(PlaybackSignalSpeedChanged)) {
speed_slider.set_value(playback->speed);
speed_slider.set_value(playback->GetSpeed());
}
if (signals_handleable.signal_unexpected(PlaybackSignalTempoChanged)) {
tempo_slider.set_value(playback->tempo);
tempo_slider.set_value(playback->GetTempo());
}
if (!running) {
timer_stopped = true;
@ -126,10 +155,15 @@ bool MainWindow::update() {
void MainWindow::expect_signal(uint16_t signal) {
expected_signals |= signal;
}
MainWindow::MainWindow(Playback *playback)
void MainWindow::update_dark_mode() {
Gtk::Settings::get_default()->set_property("gtk-application-prefer-dark-theme", Looper::Options::get_option<bool>("ui.gtk.dark_mode", false));
}
MainWindow::MainWindow(Playback *playback, Glib::RefPtr<Gtk::Application> app)
: playback(playback),
open_dialog("Open some music...")
{
set_application(app);
update_dark_mode();
open_dialog.set_transient_for(*this);
open_dialog.set_modal(true);
open_dialog.signal_response().connect([this](int response) {
@ -147,13 +181,43 @@ MainWindow::MainWindow(Playback *playback)
open_dialog.add_filter(filter_text);
set_title("Looper");
set_icon_name("looper");
set_default_size(400, 400);
openBtn.set_label("Open...");
openBtn.set_icon_name("folder-open-symbolic");
openBtn.signal_clicked().connect([this]() {
set_name("main-window");
add_action("about_window", [this]() {
aboutWindow.present();
});
add_action("options_window", [this]() {
optionsWindow.present();
});
add_action("open_file", [this]() {
this->open_dialog.present();
});
topToolbar.set_orientation(Gtk::Orientation::HORIZONTAL);
add_action("toggle_pause", [this]() {
this->expect_signal((this->playback->IsPaused() ? PlaybackSignalResumed : PlaybackSignalPaused));
this->playback->Pause();
});
add_action("stop_playback", [this]() {
this->playback->Stop();
});
add_action("restart_playback", [this]() {
this->expect_signal(PlaybackSignalSeeked);
this->playback->Seek(0.0);
});
titleBox.set_orientation(Gtk::Orientation::VERTICAL);
titleBox.set_valign(Gtk::Align::CENTER);
titleLabel.set_text(get_title());
titleLabel.set_css_classes({"title"});
subTitleLabel.set_visible(false);
subTitleLabel.set_css_classes({"subtitle"});
titleLabel.insert_at_end(titleBox);
subTitleLabel.insert_at_end(titleBox);
headerBar.set_title_widget(titleBox);
set_default_size(400, 400);
openBtn.set_label("Open...");
openBtn.set_name("open-btn");
openBtn.set_icon_name("folder-open");
openBtn.set_action_name("win.open_file");
headerBar.pack_start(openBtn);
running = true;
timer_stopped = false;
timer_stopped_condition = (GCond*)malloc(sizeof(GCond));
@ -162,92 +226,99 @@ MainWindow::MainWindow(Playback *playback)
g_mutex_init(timer_mutex);
top_box.set_orientation(Gtk::Orientation::HORIZONTAL);
top_box.set_name("top-box");
bottom_box.set_orientation(Gtk::Orientation::HORIZONTAL);
bottom_box.set_name("bottom-box");
controls_box.set_orientation(Gtk::Orientation::VERTICAL);
controls_box.set_name("controls-box");
main_box.set_orientation(Gtk::Orientation::VERTICAL);
main_box.set_name("main-box");
//main_box.set_valign(Gtk::Align::END);
main_box.set_vexpand(true);
top_box.insert_at_end(main_box);
bottom_box.insert_at_end(main_box);
pause_btn.signal_clicked().connect([this]() {
this->expect_signal((this->playback->IsPaused() ? PlaybackSignalResumed : PlaybackSignalPaused));
this->playback->Pause();
});
controls_box.insert_at_end(main_box);
top_box.insert_at_end(controls_box);
bottom_box.insert_at_end(controls_box);
pause_btn.set_action_name("win.toggle_pause");
pause_btn.set_name("pause-btn");
pause_btn.insert_at_end(top_box);
restart_btn.set_icon_name("view-refresh-symbolic");
restart_btn.signal_clicked().connect([this]() {
this->expect_signal(PlaybackSignalSeeked);
this->playback->Seek(0.0);
});
restart_btn.set_name("restart-btn");
restart_btn.set_icon_name("view-refresh");
restart_btn.set_action_name("win.restart_playback");
restart_btn.insert_at_end(top_box);
time_label.set_name("time-label");
time_label.insert_at_end(top_box);
seek_indeterminate.set_name("seek-placeholder");
seek_indeterminate.set_text("");
seek_indeterminate.set_hexpand(true);
seek_indeterminate.insert_at_end(top_box);
seek_bar.signal_value_changed().connect([this]() {
seek_bar.signal_change_value().connect([this](Gtk::ScrollType scrollType, double value) -> bool {
this->expect_signal(PlaybackSignalSeeked);
this->playback->Seek(seek_bar.get_value());
});
this->playback->Seek(value);
return true;
}, true);
seek_bar.set_hexpand();
seek_bar.set_name("seek-bar");
seek_bar.insert_at_end(top_box);
length_label.set_name("length-label");
length_label.insert_at_end(top_box);
stop_btn.signal_clicked().connect([this]() {
this->expect_signal(PlaybackSignalStopped);
this->playback->Stop();
});
stop_btn.set_icon_name("media-playback-stop-symbolic");
stop_btn.set_action_name("win.stop_playback");
stop_btn.set_name("stop-btn");
stop_btn.set_icon_name("media-playback-stop");
stop_btn.insert_at_end(top_box);
volume_slider.set_min_value(0.0);
volume_slider.set_max_value(100.0);
volume_slider.set_digits_after_decimal(0);
volume_slider.set_suffix("%");
volume_slider.set_prefix("Volume: ");
volume_slider.set_name("volume-slider");
volume_slider.value_changed.connect([this](double value) {
this->playback->volume = value;
this->playback->Update();
this->playback->SetVolume(value);
});
volume_slider.set_hexpand(false);
volume_slider.insert_at_end(top_box);
speed_slider.set_hexpand();
speed_slider.set_digits_after_decimal(2);
speed_slider.set_prefix("Speed: ");
speed_slider.set_suffix("x");
speed_slider.set_max_value(playback->MaxSpeed);
speed_slider.set_min_value(playback->MinSpeed);
speed_slider.set_value(playback->speed);
speed_slider.set_min_value(0.25);
speed_slider.set_max_value(4);
speed_slider.set_value(playback->GetSpeed());
speed_slider.set_name("speed-slider");
speed_slider.value_changed.connect([this](double value) {
this->expect_signal(PlaybackSignalSpeedChanged);
this->playback->speed = value;
this->playback->Update();
this->playback->SetSpeed(value);
});
speed_slider.insert_at_end(bottom_box);
tempo_slider.set_hexpand();
tempo_slider.set_digits_after_decimal(2);
tempo_slider.set_prefix("Tempo: ");
tempo_slider.set_suffix("x");
tempo_slider.set_max_value(playback->MaxTempo);
tempo_slider.set_min_value(playback->MinTempo);
tempo_slider.set_value(playback->tempo);
tempo_slider.set_min_value(0.25);
tempo_slider.set_max_value(4);
tempo_slider.set_value(playback->GetTempo());
tempo_slider.set_name("tempo-slider");
tempo_slider.value_changed.connect([this](double value) {
this->expect_signal(PlaybackSignalTempoChanged);
this->playback->tempo = value;
this->playback->Update();
this->playback->SetTempo(value);
});
tempo_slider.insert_at_end(bottom_box);
pitch_slider.set_hexpand();
pitch_slider.set_digits_after_decimal(2);
pitch_slider.set_prefix("Pitch: ");
pitch_slider.set_suffix("x");
pitch_slider.set_max_value(playback->MaxPitch);
pitch_slider.set_min_value(playback->MinPitch);
pitch_slider.set_value(playback->pitch);
pitch_slider.set_min_value(0.25);
pitch_slider.set_max_value(4);
pitch_slider.set_value(playback->GetPitch());
pitch_slider.set_name("pitch-slider");
pitch_slider.value_changed.connect([this](double value) {
this->expect_signal(PlaybackSignalPitchChanged);
this->playback->pitch = value;
this->playback->Update();
this->playback->SetPitch(value);
});
pitch_slider.insert_at_end(bottom_box);
dropSpaceLabel.set_text("Drop a music file here to play it...");
dropSpaceLabel.set_can_focus(false);
dropSpaceLabel.set_can_target(false);
dropSpaceLabel.set_name("drop-space-label");
dropSpace.set_can_target(true);
dropTarget = Gtk::DropTarget::create(G_TYPE_FILE, Gdk::DragAction::LINK);
dropSpace.add_controller(dropTarget);
@ -255,6 +326,7 @@ MainWindow::MainWindow(Playback *playback)
dropSpace.set_vexpand(true);
dropSpace.set_hexpand(true);
dropSpace.set_vexpand_set();
dropSpace.set_name("drop-space");
dropTarget->signal_drop().connect([this](const Glib::ValueBase &value, double a, double b) {
auto obj = g_value_get_object(value.gobj());
g_object_ref(obj);
@ -264,26 +336,45 @@ MainWindow::MainWindow(Playback *playback)
return false;
}, false);
dropSpace.insert_at_start(main_box);
topToolbar.insert_at_start(main_box);
set_child(main_box);
update_file(playback->get_current_file());
pitch_slider.set_value(playback->pitch);
speed_slider.set_value(playback->speed);
tempo_slider.set_value(playback->tempo);
volume_slider.set_value(playback->volume);
pitch_slider.set_value(playback->GetPitch(), true);
speed_slider.set_value(playback->GetSpeed(), true);
tempo_slider.set_value(playback->GetTempo(), true);
volume_slider.set_value(playback->GetVolume(), true);
optionsWindow.set_visible(false);
optionsWindow.set_transient_for(*this);
optionsWindow.set_hide_on_close(true);
optionsWindow.set_modal();
settingsBtn.set_icon_name("preferences-other-symbolic");
settingsBtn.signal_clicked().connect([this]() {
optionsWindow.present();
});
headerBar.pack_start(openBtn);
headerBar.pack_end(settingsBtn);
aboutWindow.set_visible(false);
aboutWindow.set_transient_for(*this);
aboutWindow.set_hide_on_close(true);
aboutWindow.set_modal();
main_menu = Gio::Menu::create();
auto file_menu = Gio::Menu::create();
file_menu->append("Open...", "win.open_file");
file_menu->append("About...", "win.about_window");
file_menu->append("Options...", "win.options_window");
file_menu->append("Quit", "app.quit");
auto playback_menu = Gio::Menu::create();
playback_menu->append("Pause/Resume", "win.toggle_pause");
playback_menu->append("Restart from Beginning", "win.restart_playback");
playback_menu->append("Stop", "win.stop_playback");
main_menu->append_submenu("File", file_menu);
main_menu->append_submenu("Playback", playback_menu);
app->set_menubar(main_menu);
options_menu = Gio::Menu::create();
options_menu->append("About", "win.about_window");
options_menu->append("Options", "win.options_window");
set_show_menubar(false);
menuPopover.set_menu_model(options_menu);
menuPopover.set_autohide();
menuBtn.set_popover(menuPopover);
menuBtn.set_icon_name("application-menu");
headerBar.pack_end(menuBtn);
optionsWindow.optionsSaved.connect(sigc::mem_fun(*this, &MainWindow::update_dark_mode));
set_titlebar(headerBar);
Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::update), 20);
Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::update), 100);
}
MainWindow::~MainWindow() {
running = false;

View file

@ -2,14 +2,23 @@
#include <gtkmm.h>
#include "my_slider.hpp"
#include "options_window.hpp"
#include "theme.hpp"
#include "about_window.hpp"
#include <playback.h>
class MainWindow : public Gtk::ApplicationWindow {
Gtk::Button openBtn;
Gtk::Button settingsBtn;
Gtk::MenuButton menuBtn;
Gtk::PopoverMenu menuPopover;
Glib::RefPtr<Gio::Menu> main_menu;
Glib::RefPtr<Gio::Menu> options_menu;
OptionsWindow optionsWindow;
AboutWindow aboutWindow;
Gtk::HeaderBar headerBar;
Gtk::Box topToolbar;
Gtk::Frame dropSpace;
Gtk::Box titleBox;
Gtk::Label titleLabel;
Gtk::Label subTitleLabel;
void set_subtitle(std::optional<Glib::ustring> subtitle = {});
Glib::RefPtr<Gtk::DropTarget> dropTarget;
Gtk::Label dropSpaceLabel;
Gtk::Button pause_btn;
@ -24,8 +33,10 @@ class MainWindow : public Gtk::ApplicationWindow {
MySlider speed_slider;
MySlider tempo_slider;
MySlider pitch_slider;
void update_dark_mode();
Gtk::Box top_box;
Gtk::Box bottom_box;
Gtk::Box controls_box;
Gtk::Box main_box;
bool paused;
std::optional<std::string> playback_file;
@ -43,6 +54,6 @@ class MainWindow : public Gtk::ApplicationWindow {
bool timer_stopped;
GCond *timer_stopped_condition;
GMutex *timer_mutex;
MainWindow(Playback *playback);
MainWindow(Playback *playback, Glib::RefPtr<Gtk::Application> app);
~MainWindow();
};

View file

@ -17,30 +17,41 @@ void MySlider::update(bool force) {
} catch (std::invalid_argument) {
}
if (force || text_editing) {
update_slider(value);
}
if (force || !text_editing) {
update_text_entry(value_str);
}
if (text_editing) {
edit_btn.set_icon_name("document-save-symbolic");
} else {
edit_btn.set_icon_name("edit-symbolic");
}
std::vector<Glib::ustring> classes;
classes.push_back("precise-slider");
if (text_editing) {
classes.push_back("text-editing");
}
if (get_hexpand()) {
classes.push_back("hexpand");
}
set_css_classes(classes);
if (min_value <= max_value) {
slider.set_range(min_value, max_value);
}
prefix_label.set_text(prefix);
value_label.set_text(value_str.c_str());
suffix_label.set_text(suffix);
text_entry.set_visible(text_editing);
value_label.set_visible(!text_editing);
slider.set_visible(!text_editing);
if (force || text_editing) {
update_slider(value);
}
if (force || !text_editing) {
update_text_entry(value_str);
}
update_occurring = false;
}
void MySlider::set_value(double value) {
void MySlider::set_value(double value, bool force) {
this->value = value;
update(true);
update(force);
}
Glib::ustring MySlider::get_prefix() {
return prefix;
@ -59,6 +70,7 @@ unsigned MySlider::get_digits_after_decimal() {
}
void MySlider::set_digits_after_decimal(unsigned value) {
digits_after_decimal = value;
slider.set_digits(digits_after_decimal);
}
void MySlider::update_text_entry(std::string text) {
text_entry.delete_text(0, text_entry.get_text_length());
@ -81,20 +93,37 @@ void MySlider::set_max_value(double value) {
max_value = value;
}
MySlider::MySlider() {
min_value = 0;
max_value = 1;
value = 0;
text_valid = false;
text_editing = false;
update_occurring = false;
prefix = "";
suffix = "";
digits_after_decimal = 0;
prefix_label.set_css_classes({"prefix-label"});
prefix_label.insert_at_end(*this);
value_label.set_css_classes({"value-label"});
value_label.insert_at_end(*this);
slider.set_hexpand(true);
text_entry.set_hexpand(true);
slider.insert_at_end(*this);
slider.set_css_classes({"imprecise-slider"});
text_entry.set_css_classes({"precise-number-editor"});
slider.set_hexpand();
slider.set_size_request(100);
text_entry.set_hexpand();
text_entry.insert_at_end(*this);
suffix_label.set_css_classes({"suffix-label"});
suffix_label.insert_at_end(*this);
slider.insert_at_end(*this);
edit_btn.insert_at_end(*this);
edit_btn.signal_clicked().connect([=]() {
edit_btn.set_css_classes({"edit-btn"});
edit_btn.signal_clicked().connect([this]() {
update();
text_editing = !text_editing;
update();
});
text_entry.signal_changed().connect([=]() {
text_entry.property_width_chars().set_value(0);
text_entry.signal_changed().connect([this]() {
try {
value = std::stod(text_entry.get_text().c_str());
text_valid = true;
@ -108,10 +137,10 @@ MySlider::MySlider() {
}
update();
});
slider.signal_value_changed().connect([=]() {
slider.signal_value_changed().connect([this]() {
value = slider.get_value();
value_changed.emit(value);
update();
});
update();
update(true);
}

View file

@ -1,7 +1,7 @@
#pragma once
#include <gtkmm.h>
#include <glibmm.h>
#include "theme.hpp"
class MySlider : public Gtk::Box {
double value;
double max_value;
@ -23,7 +23,7 @@ class MySlider : public Gtk::Box {
unsigned digits_after_decimal;
public:
double get_value();
void set_value(double value);
void set_value(double value, bool force = false);
sigc::signal<void(double)> value_changed;
double get_max_value();
void set_max_value(double value);
@ -35,5 +35,6 @@ class MySlider : public Gtk::Box {
void set_suffix(Glib::ustring value);
unsigned get_digits_after_decimal();
void set_digits_after_decimal(unsigned value);
MySlider();
};

View file

@ -12,10 +12,25 @@ UIBackendColumns::UIBackendColumns(const Glib::ustring &id, const Glib::ustring
void OptionsWindow::add_option(Glib::ustring title, Gtk::Widget *widget, std::string key) {
mainBox.insert_row(mainBoxRow);
Gtk::Label *label = new Gtk::Label();
label->set_css_classes({"option-label"});
label->set_justify(Gtk::Justification::LEFT);
label->set_hexpand(false);
label->set_text(title);
mainBox.attach(*label, 0, mainBoxRow);
optionWidgets.push_back(label);
mainBox.attach(*widget, 1, mainBoxRow);
Gtk::Label *emptyLabel = new Gtk::Label();
emptyLabel->set_hexpand(true);
emptyLabel->set_text("");
mainBox.attach(*emptyLabel, 1, mainBoxRow);
optionWidgets.push_back(emptyLabel);
auto widget_css_classes = widget->get_css_classes();
widget_css_classes.push_back("option-editor");
widget->set_css_classes(widget_css_classes);
if (!widget->get_hexpand()) {
widget->set_halign(Gtk::Align::END);
}
mainBox.attach(*widget, 2, mainBoxRow);
optionWidgets.push_back(widget);
mainBoxRow++;
modifiableOptions.insert(key);
@ -29,14 +44,20 @@ void OptionsWindow::revert() {
}
void OptionsWindow::save() {
Looper::Options::save_options();
optionsSaved.emit();
savedOptionRequiresRestart = needsRestartLabel.get_visible();
}
OptionsWindow::OptionsWindow() {
set_title("Options...");
set_icon_name("preferences-other");
set_name("options-window");
rootBox.set_name("options-window-root");
mainBox.set_expand();
mainBox.insert_column(0);
mainBox.insert_column(1);
mainBox.insert_column(2);
mainBox.set_name("options-main-box");
needsRestartLabel.set_name("options-needs-restart-label");
needsRestartLabel.set_text("A restart is needed to apply some changes.");
needsRestartLabel.set_visible(false);
needsRestartLabel.insert_at_start(rootBox);
@ -62,14 +83,16 @@ OptionsWindow::OptionsWindow() {
if (!col) return;
auto box = dynamic_cast<Gtk::Box*>(list_item->get_child());
if (!box) return;
box->set_css_classes({"ui-backend-option"});
auto name_label = dynamic_cast<Gtk::Label*>(box->get_first_child());
name_label->set_hexpand();
name_label->set_text(col->backendName);
name_label->set_css_classes({"ui-backend-name", "primary"});
if (!name_label) return;
auto id_label = dynamic_cast<Gtk::Label*>(name_label->get_next_sibling());
if (!id_label) return;
id_label->set_opacity(0.5);
id_label->set_text(col->backendId);
id_label->set_css_classes({"ui-backend-id", "secondary"});
});
uiBackendBox->set_factory(factory);
uiBackendBox->property_selected().signal_changed().connect([uiBackendBox, listStore, this]() {
@ -78,21 +101,39 @@ OptionsWindow::OptionsWindow() {
this->needsRestartLabel.set_visible();
});
add_option("UI frontend", uiBackendBox, "ui.frontend");
optionChanged.connect([this, uiBackendBox, listStore](std::string key) {
Gtk::Switch *darkModeSwitch = new Gtk::Switch();
darkModeSwitch->set_active(Looper::Options::get_option<bool>("ui.gtk.dark_mode", false));
darkModeSwitch->property_active().signal_changed().connect([this, darkModeSwitch]() {
Looper::Options::set_option<bool>("ui.gtk.dark_mode", darkModeSwitch->get_active());
});
add_option("Dark mode", darkModeSwitch, "ui.gtk.dark_mode");
optionChanged.connect([this, uiBackendBox, listStore, darkModeSwitch](std::string key) {
if (key == "ui.frontend") {
std::string frontend = Looper::Options::get_option<std::string>("ui.frontend");
std::string frontend = Looper::Options::get_option<std::string>(key);
for (int i = 0; i < listStore->get_n_items(); i++) {
if (std::string(listStore->get_item(i)->backendId.c_str()) == frontend) {
uiBackendBox->set_selected(i);
break;
}
}
} else if (key == "ui.gtk.dark_mode") {
darkModeSwitch->set_active(Looper::Options::get_option<bool>(key));
}
});
mainBox.set_row_spacing(2);
mainBox.set_column_spacing(2);
mainBox.insert_at_end(rootBox);
okBtn.set_name("options-ok-btn");
okBtn.set_css_classes({"options-window-btn"});
okBtn.set_label("OK");
cancelBtn.set_name("options-cancel-btn");
cancelBtn.set_css_classes({"options-window-btn"});
cancelBtn.set_label("Cancel");
saveBtn.set_name("options-save-btn");
saveBtn.set_css_classes({"options-window-btn"});
saveBtn.set_label("Save");
revertBtn.set_name("options-revert-btn");
revertBtn.set_css_classes({"options-window-btn"});
revertBtn.set_label("Revert");
okBtn.signal_clicked().connect([this]() {
this->save();
@ -112,11 +153,19 @@ OptionsWindow::OptionsWindow() {
saveBtn.insert_at_end(btnBox);
revertBtn.insert_at_end(btnBox);
cancelBtn.insert_at_end(btnBox);
rootBox.set_spacing(8);
btnBox.set_spacing(2);
btnBox.set_orientation(Gtk::Orientation::HORIZONTAL);
btnBox.set_name("options-window-btns");
btnBox.set_halign(Gtk::Align::END);
btnBox.insert_at_end(rootBox);
rootBox.set_orientation(Gtk::Orientation::VERTICAL);
rootBox.set_expand();
set_child(rootBox);
Gtk::Requisition min;
Gtk::Requisition nat;
rootBox.get_preferred_size(min, nat);
set_default_size(nat.get_width(), nat.get_height());
}
OptionsWindow::~OptionsWindow() {
for (auto widget : optionWidgets) {

View file

@ -30,6 +30,7 @@ class OptionsWindow : public Gtk::Window {
void save();
void add_option(Glib::ustring title, Gtk::Widget *widget, std::string key);
public:
sigc::signal<void()> optionsSaved;
template<class T>
void change_option(std::string key, T value) {
Looper::Options::set_option<T>(key, value);

View file

@ -0,0 +1 @@
#include "theme.hpp"

View file

@ -0,0 +1,6 @@
#pragma once
#include <gtkmm.h>
#include <log.hpp>
class Theme {
};

View file

@ -1,15 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
<cambalache-project version="0.13.1" target_tk="gtk-4.0">
<ui>
(1,None,"main_window.ui","main_window.ui",None,None,None,None,None,None,None)
</ui>
<object>
(1,1,"GtkApplicationWindow",None,None,None,None,None,-1,None),
(1,2,"GtkHeaderBar",None,1,None,"titlebar",None,-1,None),
(1,3,"GtkButton",None,2,None,None,None,-1,None)
</object>
<object_property>
(1,1,"GtkWindow","title","Looper",None,None,None,None,None,None,None,None,None)
</object_property>
</cambalache-project>

View file

@ -37,6 +37,9 @@ else()
endif()
find_package(OpenGL REQUIRED COMPONENTS ${GLComponents})
add_ui_backend(imgui_ui ${BACKEND_IMGUI_SRC})
if(${USE_GLES})
target_compile_definitions(imgui_ui PRIVATE "IMGUI_IMPL_OPENGL_ES2")
endif()
target_link_libraries(imgui_ui PRIVATE OpenGL::${GLTarget} SDL2::SDL2 SDL2_image::SDL2_image)
target_include_directories(imgui_ui PRIVATE ${BACKEND_IMGUI_INC})
target_compile_definitions(imgui_ui PRIVATE IMGUI_USER_CONFIG="imgui_config.h")

View file

@ -100,11 +100,9 @@ void MainLoop::GuiFunction() {
length = playback->GetLength();
// Set the window title if the file changed, or playback stopped.
if (playback->handle_signals(PlaybackSignalFileChanged|PlaybackSignalStopped)) {
auto file_maybe = playback->get_current_file();
auto file_maybe = playback->get_current_title();
if (file_maybe.has_value()) {
auto file = file_maybe.value();
std::filesystem::path fpath(file);
std::string name = fpath.stem().string();
auto name = file_maybe.value();
SetWindowTitle((name + std::string(" - Looper")).c_str());
} else {
SetWindowTitle("Looper");
@ -134,7 +132,7 @@ void MainLoop::GuiFunction() {
}
ImGui::EndMenu();
}
#ifdef DEBUG
#ifdef DEBUG_MODE
if (ImGui::BeginMenu(_TRI_CTX(ICON_FK_COG, "Main menu (in debug builds)", "Debug"))) {
if (ImGui::MenuItem(_TR_CTX("Main menu | Debug", "Show ImGui Demo Window"), nullptr, show_demo_window)) {
show_demo_window = !show_demo_window;
@ -163,37 +161,42 @@ void MainLoop::GuiFunction() {
}
ImGui::SameLine();
const int NEXT_SLIDER_COUNT = 1;
ImGui::SetNextItemWidth(-(ImGui::GetFontSize() * (1 + (8 * NEXT_SLIDER_COUNT))) - ((ImGui::GetStyle().ItemSpacing.x + ImGui::GetStyle().FramePadding.x) * (NEXT_SLIDER_COUNT + 1)));
double seek_bar_width = -(ImGui::GetFontSize() * (1 + (8 * NEXT_SLIDER_COUNT))) - ((ImGui::GetStyle().ItemSpacing.x + ImGui::GetStyle().FramePadding.x) * (NEXT_SLIDER_COUNT + 1));
if (lengthKnown) {
ImGui::SetNextItemWidth(seek_bar_width);
uint8_t components = TimeToComponentCount(playback->GetLength());
string time_str = TimeToString(position, components);
string time_str = TimeToString(position, components) + "/" + TimeToString(length, components);
if (ImGui::SliderFloat("##Seek", &position, 0.0f, playback->GetLength(), time_str.c_str(), ImGuiSliderFlags_NoRoundToFormat))
playback->Seek(position);
} else {
ImGui::TextUnformatted("");
ImVec2 size(seek_bar_width, ImGui::GetFrameHeight());
ImGui::InvisibleButton("##SeekIndeterminate", size);
}
ImGui::SameLine();
if (ImGui::Button(ICON_FK_STOP "##Stop")) {
playback->Stop();
}
float pitch = playback->GetPitch(), tempo = playback->GetTempo(), speed = playback->GetSpeed(), volume = playback->GetVolume();
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
if (ImGui::SliderFloat("##Volume", &playback->volume, 0.0, 100.0, ICON_FK_VOLUME_UP ": %.0f%%")) {
playback->Update();
if (ImGui::SliderFloat("##Volume", &volume, 0.0, 100.0, ICON_FK_VOLUME_UP ": %.0f%%")) {
playback->SetVolume(volume);
}
const float items = 3.0f;
const float between_items = items - 1.0f;
ImGui::PushItemWidth((ImGui::GetWindowWidth() / items) - (ImGui::GetStyle().ItemSpacing.x / (items / between_items)) - ((ImGui::GetStyle().WindowPadding.x / items) * 2.0f));
if (ImGui::SliderFloat("##Speed", &playback->speed, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Speed: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->Update();
if (ImGui::SliderFloat("##Speed", &speed, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Speed: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->SetSpeed(speed);
}
ImGui::SameLine();
if (ImGui::SliderFloat("##Tempo", &playback->tempo, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Tempo: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->Update();
if (ImGui::SliderFloat("##Tempo", &tempo, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Tempo: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->SetTempo(tempo);
}
ImGui::SameLine();
if (ImGui::SliderFloat("##Pitch", &playback->pitch, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Pitch: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->Update();
if (ImGui::SliderFloat("##Pitch", &pitch, 0.25, 4.0, _TR_CTX("Playback controls | slider", "Pitch: %.2fx"), ImGuiSliderFlags_Logarithmic)) {
playback->SetPitch(pitch);
}
ImGui::PopItemWidth();
}
@ -205,13 +208,17 @@ void MainLoop::GuiFunction() {
static std::string set_backend_name = cur_backend->get_name();
static std::string set_backend_id = cur_backend->get_id();
if (ImGui::BeginCombo("UI backend", set_backend_name.c_str())) {
if (restart_needed) {
ImGui::TextUnformatted(_TR("A restart is needed to apply some changes."));
}
if (ImGui::BeginCombo(_TR("UI frontend"), set_backend_name.c_str())) {
for (auto &backend : backends) {
bool is_current = set_backend_id == backend->get_id();
if (ImGui::Selectable(backend->get_name().c_str(), &is_current)) {
set_backend_id = backend->get_id();
set_backend_name = backend->get_name();
Looper::Options::set_option("ui.backend", set_backend_id);
Looper::Options::set_option("ui.frontend", set_backend_id);
restart_needed = true;
}
if (is_current) {
ImGui::SetItemDefaultFocus();
@ -302,52 +309,15 @@ void MainLoop::GuiFunction() {
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, 0.0f, VER_STRING.c_str()).x) / 2.0f);
ImGui::Text(VER_STRING.c_str());
ImGui::NewLine();
static vector<LicenseData> projects = {
LicenseData(APP_NAME_STR, "MIT"),
LicenseData(_TR_CTX("Library name", "SDL Mixer X"), "Zlib"),
LicenseData(_TR_CTX("Library name", "CLI11"), "BSD-3-Clause"),
LicenseData(_TR_CTX("Library name", "JsonCpp"), "MIT"),
LicenseData(_TR_CTX("Library name", "SoundTouch"), "LGPL-2.1-only"),
LicenseData(_TR_CTX("Library name", "libintl"), "LGPL-2.1-only"),
LicenseData(_TR_CTX("Library name", "Dear ImGui"), "MIT"),
LicenseData(_TR_CTX("Library name", "imgui-filebrowser"), "MIT"),
#ifdef PORTALS
LicenseData(_TR_CTX("Library name", "libportal"), "LGPL-3.0-only"), // Only include the license if it applies.
#endif
LicenseData(_TR_CTX("Library name", "Noto Sans"), "OFL-1.1-RFN"),
LicenseData(_TR_CTX("Library name", "Fork Awesome"), "OFL-1.1-RFN"),
LicenseData(_TR_CTX("Library name", "IconFontCppHeaders"), "Zlib"),
LicenseData(_TR_CTX("Library name", "TOML++"), "MIT")
};
// Do this in an inner scope so that 'i' isn't accidentally used outside it,
// and so that 'i' can refer to another variable such as in a for loop.
{
int i = 0;
// Use a variable instead of hardcoding so that a #ifdef can change the indices later on.
LOAD_LICENSE(projects[i], looper); i++;
LOAD_LICENSE(projects[i], sdl_mixer_x); i++;
LOAD_LICENSE(projects[i], cli11); i++;
LOAD_LICENSE(projects[i], jsoncpp); i++;
LOAD_LICENSE(projects[i], soundtouch); i++;
LOAD_LICENSE(projects[i], libintl); i++;
LOAD_LICENSE(projects[i], imgui); i++;
LOAD_LICENSE(projects[i], imgui_filebrowser); i++;
#ifdef PORTALS
LOAD_LICENSE(projects[i], libportal); i++;
#endif
LOAD_LICENSE(projects[i], notosans); i++;
LOAD_LICENSE(projects[i], forkawesome); i++;
LOAD_LICENSE(projects[i], icnfntcpphdrs); i++;
LOAD_LICENSE(projects[i], tomlplusplus); i++;
}
auto &license_data = get_license_data();
// Left
static LicenseData selected = projects[0];
static LicenseData selected = *license_data.begin();
{
ImGui::BeginGroup();
ImGui::TextUnformatted(_TR_CTX("Project selector label.", "Project"));
// Next string is internal.
ImGui::BeginChild("project selector", ImVec2(150, 0), true);
for (auto project : projects)
for (auto project : license_data)
{
if (ImGui::Selectable(project.Project.c_str(), selected.Project == project.Project))
selected = project;
@ -396,7 +366,6 @@ void MainLoop::LoadFile(std::string file) {
playback->Start(file);
}
void MainLoop::Deinit() {
delete playback;
{
Json::Value config;
@ -451,3 +420,35 @@ int ImGuiUIBackend::run(std::vector<std::string> realArgs, int argc, char** argv
loop.args = args;
return loop.Run();
}
void ImGuiUIBackend::add_licenses() {
auto &license_data = get_license_data();
auto glib = LicenseData("Glib", "lgpl-2.1-or-later");
auto imgui = LicenseData("Dear ImGui", "MIT");
auto libintl = LicenseData("libintl", "LGPL-2.1-only");
auto imfb = LicenseData("imgui-filebrowser", "MIT");
auto noto = LicenseData("Noto Sans", "OFL-1.1-RFN");
auto noto_jp = LicenseData("Noto Sans JP", "OFL-1.1-RFN");
auto fork_awesome = LicenseData("Fork Awesome", "OFL-1.1-RFN");
auto ifch = LicenseData("IconFontCppHeaders", "Zlib");
LOAD_LICENSE(glib, lgpl_2_1);
LOAD_LICENSE(imgui, imgui);
LOAD_LICENSE(libintl, lgpl_2_1);
LOAD_LICENSE(imfb, imgui_filebrowser);
LOAD_LICENSE(noto, notosans);
LOAD_LICENSE(noto_jp, notosansjp);
LOAD_LICENSE(fork_awesome, forkawesome);
LOAD_LICENSE(ifch, icnfntcpphdrs);
license_data.insert(glib);
license_data.insert(imgui);
license_data.insert(libintl);
license_data.insert(imfb);
license_data.insert(noto);
license_data.insert(noto_jp);
license_data.insert(fork_awesome);
license_data.insert(ifch);
#ifdef PORTALS
auto libportal = LicenseData("libportal", "LGPL-3.0-only");
LOAD_LICENSE(libportal, lgpl_3_0);
license_data.insert(libportal);
#endif
}

View file

@ -23,7 +23,7 @@
#else
#include <SDL_opengl.h>
#endif
#include "license.h"
#include <license.hpp>
#include "base85.h"
#include "IconFontCppHeaders/IconsForkAwesome.h"
#include "imgui/imgui.h"
@ -36,6 +36,7 @@
using namespace std::filesystem;
using namespace std::numbers;
using std::string;
#define IMGUI_FRONTEND
class MainLoop : public RendererBackend {
bool show_demo_window = false;
FileBrowser fileDialog = FileBrowser(false);
@ -45,6 +46,7 @@ class MainLoop : public RendererBackend {
bool prefs_window = false;
bool theme_editor = false;
bool about_window = false;
bool restart_needed = false;
bool stopped = true;
std::vector<UIBackend*> backends;
UIBackend *cur_backend;

View file

@ -7,5 +7,6 @@ class ImGuiUIBackend : public UIBackend {
std::string get_id() override;
std::string get_name() override;
int run(std::vector<std::string> realArgs, int argc, char **argv) override;
void add_licenses() override;
ImGuiUIBackend() = default;
};

View file

@ -1,4 +1,8 @@
#pragma once
#define TAG "@TAG@"
#define LOCALE_DIR "@LOCALE_DIR@"
#cmakedefine DEBUG
#cmakedefine01 DEBUG_MODE_VALUE
#if DEBUG_MODE_VALUE==1
#define DEBUG_MODE
#endif
#undef DEBUG_MODE_VALUE

View file

@ -1,4 +0,0 @@
#pragma once
#define TAG "@TAG@"
#define LOCALE_DIR "@LOCALE_DIR@"
#mesondefine DEBUG

135
dbus.cpp
View file

@ -12,25 +12,98 @@ DBusAPI::DBusAPI(Playback *playback) {
call >> filePath;
this->playback->Start(filePath);
});
api->registerMethod(interfaceName, "setSpeed", "d", "", [this](sdbus::MethodCall call) {
api->registerSignal(interfaceName, "playbackEngineStarted", "");
api->registerSignal(interfaceName, "speedChanged", "d");
api->registerSignal(interfaceName, "tempoChanged", "d");
api->registerSignal(interfaceName, "pitchChanged", "d");
api->registerSignal(interfaceName, "pauseChanged", "b");
api->registerSignal(interfaceName, "stopped", "");
api->registerSignal(interfaceName, "errorOccurred", "s");
api->registerSignal(interfaceName, "seeked", "d");
api->registerSignal(interfaceName, "fileChanged", "s");
api->registerProperty(interfaceName, "speed", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetSpeed();
}, [this](sdbus::PropertySetCall set_call) {
double newValue;
call >> newValue;
this->playback->speed = newValue;
this->playback->Update();
set_call >> newValue;
this->playback->SetSpeed(newValue);
});
api->registerMethod(interfaceName, "setTempo", "d", "", [this](sdbus::MethodCall call) {
api->registerProperty(interfaceName, "tempo", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetTempo();
}, [this](sdbus::PropertySetCall set_call) {
double newValue;
call >> newValue;
this->playback->tempo = newValue;
this->playback->Update();
set_call >> newValue;
this->playback->SetTempo(newValue);
});
api->registerMethod(interfaceName, "setPitch", "d", "", [this](sdbus::MethodCall call) {
api->registerProperty(interfaceName, "pitch", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetPitch();
}, [this](sdbus::PropertySetCall set_call) {
double newValue;
call >> newValue;
this->playback->pitch = newValue;
this->playback->Update();
set_call >> newValue;
this->playback->SetPitch(newValue);
});
api->registerProperty(interfaceName, "volume", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetVolume();
}, [this](sdbus::PropertySetCall set_call) {
double newValue;
set_call >> newValue;
this->playback->SetVolume(newValue);
});
api->registerMethod(interfaceName, "stop", "", "", [this](sdbus::MethodCall call) {
this->playback->Stop();
});
api->registerMethod(interfaceName, "togglePause", "", "", [this](sdbus::MethodCall call) {
this->playback->Pause();
});
api->registerProperty(interfaceName, "paused", "b", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->IsPaused();
}, [this](sdbus::PropertySetCall call) {
bool shouldBePaused;
call >> shouldBePaused;
this->playback->SetPaused(shouldBePaused);
});
api->registerProperty(interfaceName, "stopped", "b", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->IsStopped();
});
api->registerMethod(interfaceName, "errorExists", "", "b", [this](sdbus::MethodCall call) {
auto reply = call.createReply();
reply << this->playback->ErrorExists();
});
api->registerMethod(interfaceName, "getLastError", "", "s", [this](sdbus::MethodCall call) {
auto error = this->playback->GetError();
if (error.has_value()) {
auto reply = call.createReply();
reply << error.value();
} else {
auto errorReply = call.createErrorReply(sdbus::createError(0, "No error found."));
}
});
api->registerProperty(interfaceName, "position", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetPosition();
}, [this](sdbus::PropertySetCall call) {
double value;
call >> value;
this->playback->Seek(value);
});
api->registerProperty(interfaceName, "length", "d", [this](sdbus::PropertyGetReply reply) {
reply << this->playback->GetLength();
});
api->registerProperty(interfaceName, "current_file_path", "s", [this](sdbus::PropertyGetReply reply) {
auto file_maybe = this->playback->get_current_file();
if (file_maybe.has_value()) {
reply << file_maybe.value();
} else {
reply << "";
}
});
api->registerProperty(interfaceName, "current_file_title", "s", [this](sdbus::PropertyGetReply reply) {
auto title_maybe = this->playback->get_current_title();
if (title_maybe.has_value()) {
reply << title_maybe.value();
} else {
reply << "";
}
});
api->registerSignal(interfaceName, "fileStarted", "s");
api->finishRegistration();
connection->enterEventLoopAsync();
}
@ -47,26 +120,38 @@ void DBusAPISender::playFile(std::string file) {
}
void DBusAPISender::setPitch(double value) {
if (connected) {
auto method = proxy->createMethodCall(DBusAPI::interfaceName, "setPitch");
method.dontExpectReply();
method << value;
proxy->callMethod(method);
proxy->setProperty("pitch").onInterface(DBusAPI::interfaceName).toValue(value);
}
}
void DBusAPISender::setSpeed(double value) {
if (connected) {
auto method = proxy->createMethodCall(DBusAPI::interfaceName, "setSpeed");
method.dontExpectReply();
method << value;
proxy->callMethod(method);
proxy->setProperty("speed").onInterface(DBusAPI::interfaceName).toValue(value);
}
}
void DBusAPISender::setTempo(double value) {
if (connected) {
auto method = proxy->createMethodCall(DBusAPI::interfaceName, "setTempo");
method.dontExpectReply();
method << value;
proxy->callMethod(method);
proxy->setProperty("tempo").onInterface(DBusAPI::interfaceName).toValue(value);
}
}
double DBusAPISender::getPitch() {
if (connected) {
return proxy->getProperty("pitch").onInterface(DBusAPI::interfaceName);
} else {
return -1.0;
}
}
double DBusAPISender::getTempo() {
if (connected) {
return proxy->getProperty("tempo").onInterface(DBusAPI::interfaceName);
} else {
return -1.0;
}
}
double DBusAPISender::getSpeed() {
if (connected) {
return proxy->getProperty("speed").onInterface(DBusAPI::interfaceName);
} else {
return -1.0;
}
}
DBusAPISender::DBusAPISender() {

View file

@ -21,6 +21,11 @@ class DBusAPISender {
void setPitch(double pitch);
void setTempo(double tempo);
void setSpeed(double speed);
void setVolume(double volume);
double getPitch();
double getTempo();
double getSpeed();
double getVolume();
bool isOnlyInstance();
DBusAPISender();
};

View file

@ -2,7 +2,9 @@
#include <string>
#include <vector>
#include <cstring>
#include <log.hpp>
#include <unordered_set>
#include "log.hpp"
#include "util.hpp"
using std::string;
struct LicenseData {
string Project;
@ -14,12 +16,21 @@ struct LicenseData {
memcpy(vec.data(), license_data, license_size);
vec.push_back('\0');
LicenseContents = string(vec.data());
DEBUG.writefln("Loading license for project '%s': %s...", Project, Spdx);
DEBUG.writefln("Loading license for project '%s': %s...", Project.c_str(), Spdx.c_str());
}
inline LicenseData(string project, string spdx) {
this->Project = project;
this->Spdx = spdx;
}
inline bool operator==(const LicenseData &other) const {
return Project == other.Project && Spdx == other.Spdx;
}
};
template<>
struct std::hash<LicenseData> {
inline std::size_t operator()(const LicenseData d) const noexcept {
return combine_hashes({std::hash<string>()(d.Project), std::hash<string>()(d.Spdx)});
}
};
std::unordered_set<LicenseData> &get_license_data();
#define LOAD_LICENSE(data, prefix) if (data.LicenseContents == "") data.load_contents(prefix##_license_data, prefix##_license_size);

View file

@ -3,10 +3,15 @@
#include "log.hpp"
#include "thirdparty/CLI11.hpp"
#include "data.h"
#include "license.hpp"
#include "assets/assets.h"
using namespace Looper;
using namespace Looper::Options;
using namespace Looper::Log;
std::unordered_set<LicenseData> license_data;
std::unordered_set<LicenseData> &get_license_data() {
return license_data;
}
int main(int argc, char **argv) {
std::vector<std::string> args;
for (int i = 1; i < argc; i++) {
@ -34,6 +39,32 @@ int main(int argc, char **argv) {
int new_argc = args.size();
char **new_argv = (char**)malloc(new_argc * sizeof(char*));
init_logging();
{
auto looper_mit = LicenseData("Looper (MIT)", "MIT");
auto looper_gpl = LicenseData("Looper (GPL)", "GPL-3.0-or-later");
auto looper = LicenseData("Looper", "MIT OR GPL-3.0-or-later");
auto tomlpp = LicenseData("TOML++", "MIT");
auto smx = LicenseData("SDL Mixer X", "Zlib");
auto cli11 = LicenseData("CLI11", "BSD-3-Clause");
auto jsoncpp = LicenseData("JsonCpp", "MIT");
auto soundtouch = LicenseData("SoundTouch", "LGPL-2.1-only");
LOAD_LICENSE(looper_mit, looper_mit);
LOAD_LICENSE(looper_gpl, looper_gpl);
LOAD_LICENSE(looper, looper);
LOAD_LICENSE(tomlpp, tomlplusplus);
LOAD_LICENSE(smx, sdl_mixer_x);
LOAD_LICENSE(cli11, cli11);
LOAD_LICENSE(jsoncpp, jsoncpp);
LOAD_LICENSE(soundtouch, lgpl_2_1);
license_data.insert(looper);
license_data.insert(looper_gpl);
license_data.insert(looper_mit);
license_data.insert(tomlpp);
license_data.insert(smx);
license_data.insert(cli11);
license_data.insert(jsoncpp);
license_data.insert(soundtouch);
}
DEBUG.writeln("Command line arguments after first parse:");
for (size_t i = 0; i < new_argc; i++) {
auto &arg = args[i];
@ -44,6 +75,7 @@ int main(int argc, char **argv) {
init_backends();
DEBUG.writeln("Loaded frontends: ");
for (auto kv : UIBackend::backends) {
kv.second->add_licenses();
DEBUG.writefln(" - '%s'", kv.first.c_str());
}
DEBUG.writeln("Loading options file...");

View file

@ -14,7 +14,7 @@ using namespace std::chrono;
size_t CalculateBufSize(SDL_AudioSpec *obtained, double seconds, double max_seconds, size_t samples_override = 0) {
return ((((samples_override == 0) ? obtained->samples : samples_override) * std::min(seconds, max_seconds)) + 1) * sizeof(SAMPLETYPE) * obtained->channels;
}
void Playback::SDLCallbackInner(Uint8 *stream, int len) {
void PlaybackInstance::SDLCallbackInner(Uint8 *stream, int len) {
SDL_memset((void*)stream, 0, len);
if (!playback_ready.load()) {
return;
@ -41,10 +41,10 @@ void Playback::SDLCallbackInner(Uint8 *stream, int len) {
}
st->receiveSamples((SAMPLETYPE*)stream, len / unit);
}
void Playback::SDLCallback(void *userdata, Uint8 *stream, int len) {
((Playback*)userdata)->SDLCallbackInner(stream, len);
void PlaybackInstance::SDLCallback(void *userdata, Uint8 *stream, int len) {
((PlaybackInstance*)userdata)->SDLCallbackInner(stream, len);
}
Mix_Music *Playback::Load(const char *file) {
Mix_Music *PlaybackInstance::Load(const char *file) {
{
std::filesystem::path fpath = std::string(file);
fpath = fpath.parent_path() / fpath.stem();
@ -79,18 +79,27 @@ Mix_Music *Playback::Load(const char *file) {
update.store(true);
current_file_mutex.lock();
current_file = std::string(file);
const char *title_tag = Mix_GetMusicTitleTag(output);
// Check for an empty string, which indicates there's no title tag.
if (title_tag[0] == '\0') {
std::filesystem::path path(current_file.value());
current_title = path.stem().string();
} else {
current_title = std::string(title_tag);
}
current_file_mutex.unlock();
set_signal(PlaybackSignalFileChanged);
return output;
}
void Playback::Unload(Mix_Music *music) {
void PlaybackInstance::Unload(Mix_Music *music) {
Mix_HaltMusicStream(music);
Mix_FreeMusic(music);
current_file_mutex.lock();
current_file = {};
current_title = {};
current_file_mutex.unlock();
}
void Playback::UpdateST() {
void PlaybackInstance::UpdateST() {
if (speed > 0.0f && speed_changed.exchange(false)) {
st->setRate(speed);
set_signal(PlaybackSignalSpeedChanged);
@ -104,10 +113,10 @@ void Playback::UpdateST() {
set_signal(PlaybackSignalPitchChanged);
}
}
double Playback::GetMaxSeconds() {
double PlaybackInstance::GetMaxSeconds() {
return std::max((double)(MaxSpeed * MaxTempo), st->getInputOutputSampleRatio());
}
void Playback::ThreadFunc() {
void PlaybackInstance::ThreadFunc() {
#ifdef __linux__
pthread_setname_np(pthread_self(), "Playback control thread");
#endif
@ -137,7 +146,7 @@ void Playback::ThreadFunc() {
desired.freq = 48000;
desired.samples = 1024;
desired.channels = 2;
desired.callback = Playback::SDLCallback;
desired.callback = PlaybackInstance::SDLCallback;
desired.userdata = this;
st = new SoundTouch();
Mix_Init(MIX_INIT_FLAC|MIX_INIT_MID|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG|MIX_INIT_OPUS|MIX_INIT_WAVPACK);
@ -257,7 +266,7 @@ void Playback::ThreadFunc() {
set_signal(PlaybackSignalStopped);
}
Playback::Playback() {
PlaybackInstance::PlaybackInstance() {
running = false;
paused = true;
position = 0;
@ -273,17 +282,23 @@ Playback::Playback() {
playback_ready = false;
bufsize = 0;
}
std::optional<std::string> Playback::get_current_file() {
std::optional<std::string> PlaybackInstance::get_current_file() {
current_file_mutex.lock();
std::optional<std::string> output = current_file;
current_file_mutex.unlock();
return output;
}
Playback::~Playback() {
std::optional<std::string> PlaybackInstance::get_current_title() {
current_file_mutex.lock();
std::optional<std::string> output = current_title;
current_file_mutex.unlock();
return output;
}
PlaybackInstance::~PlaybackInstance() {
Stop();
}
void Playback::Start(std::string filePath) {
void PlaybackInstance::Start(std::string filePath) {
this->filePath = filePath;
INFO.writefln("Playing %s...", filePath.c_str());
flag_mutex.lock();
@ -294,41 +309,41 @@ void Playback::Start(std::string filePath) {
if (running.exchange(true)) {
file_changed.store(true);
} else {
thread = std::thread(&Playback::ThreadFunc, this);
thread = std::thread(&PlaybackInstance::ThreadFunc, this);
}
flag_mutex.unlock();
}
double Playback::GetPosition() {
double PlaybackInstance::GetPosition() {
return position;
}
double Playback::GetLength() {
double PlaybackInstance::GetLength() {
return length;
}
void Playback::Seek(double position) {
void PlaybackInstance::Seek(double position) {
flag_mutex.lock();
this->position = position;
seeking.store(true);
flag_mutex.unlock();
}
void Playback::Pause() {
void PlaybackInstance::Pause() {
flag_mutex.lock();
paused = !paused;
pause_changed.store(true);
flag_mutex.unlock();
}
bool Playback::IsPaused() {
bool PlaybackInstance::IsPaused() {
return paused;
}
void Playback::Stop() {
void PlaybackInstance::Stop() {
if (running.exchange(false)) {
thread.join();
}
}
void Playback::Update() {
void PlaybackInstance::Update() {
if (prev_pitch != pitch) {
pitch_changed.store(true);
}
@ -341,10 +356,10 @@ void Playback::Update() {
update.store(true);
}
bool Playback::IsStopped() {
bool PlaybackInstance::IsStopped() {
return !running;
}
optional<std::string> Playback::GetError() {
optional<std::string> PlaybackInstance::GetError() {
if (ErrorExists()) {
error_mutex.lock();
std::string error = errors.back();
@ -355,18 +370,18 @@ optional<std::string> Playback::GetError() {
return {};
}
}
bool Playback::ErrorExists() {
bool PlaybackInstance::ErrorExists() {
error_mutex.lock();
bool output = !errors.empty();
error_mutex.unlock();
return output;
}
void Playback::set_signal(uint16_t signal) {
void PlaybackInstance::set_signal(uint16_t signal) {
signal_mutex.lock();
signals_occurred |= signal;
signal_mutex.unlock();
}
uint16_t Playback::handle_signals(uint16_t signals) {
uint16_t PlaybackInstance::handle_signals(uint16_t signals) {
if (signal_mutex.try_lock()) {
uint16_t output = signals_occurred & signals;
signals_occurred &= ~output;
@ -376,3 +391,31 @@ uint16_t Playback::handle_signals(uint16_t signals) {
return PlaybackSignalNone;
}
}
void PlaybackInstance::SetTempo(float tempo) {
this->tempo = tempo;
Update();
}
void PlaybackInstance::SetPitch(float pitch) {
this->pitch = pitch;
Update();
}
void PlaybackInstance::SetSpeed(float speed) {
this->speed = speed;
Update();
}
void PlaybackInstance::SetVolume(float volume) {
this->volume = volume;
Update();
}
float PlaybackInstance::GetTempo() {
return tempo;
}
float PlaybackInstance::GetPitch() {
return pitch;
}
float PlaybackInstance::GetSpeed() {
return speed;
}
float PlaybackInstance::GetVolume() {
return volume;
}

View file

@ -30,6 +30,91 @@ enum {
PlaybackSignalStarted = 1 << 9
};
class Playback {
public:
inline Playback() {};
inline virtual ~Playback() {}
inline virtual std::optional<std::string> get_current_file() {
return {};
}
inline virtual std::optional<std::string> get_current_title() {
return {};
}
inline virtual double GetPosition() {
return 0.0;
}
inline virtual double GetLength() {
return 0.0;
}
inline virtual void Seek(double position) {}
inline virtual void Start(std::string filePath) {}
inline virtual bool IsPaused() {
return true;
}
inline virtual void Pause() {}
inline virtual void Stop() {}
inline virtual bool IsStopped() {
return true;
}
inline virtual void SetTempo(float tempo) {}
inline virtual void SetSpeed(float speed) {}
inline virtual void SetPitch(float pitch) {}
inline virtual void SetVolume(float volume) {}
inline virtual float GetTempo() {
return 1.0;
}
inline virtual float GetSpeed() {
return 1.0;
}
inline virtual float GetPitch() {
return 1.0;
}
inline virtual float GetVolume() {
return 1.0;
}
inline virtual uint16_t handle_signals(uint16_t signal) {
return 0;
}
inline virtual optional<std::string> GetError() {
return {};
}
inline virtual bool ErrorExists() {
return false;
}
inline virtual void SetPaused(bool paused) {
if (IsPaused() != paused) {
Pause();
}
}
};
class DBusAPISender;
class PlaybackRemote : public Playback {
private:
DBusAPISender *sender;
public:
double GetPosition() override;
double GetLength() override;
void Seek(double position) override;
void Start(std::string filePath) override;
bool IsPaused() override;
void Pause() override;
void Stop() override;
void Update();
bool IsStopped() override;
void SetTempo(float tempo) override;
void SetPitch(float pitch) override;
void SetSpeed(float speed) override;
void SetVolume(float volume) override;
float GetTempo() override;
float GetPitch() override;
float GetSpeed() override;
float GetVolume() override;
uint16_t handle_signals(uint16_t signal) override;
optional<std::string> GetError() override;
bool ErrorExists() override;
PlaybackRemote();
};
class PlaybackInstance : public Playback {
private:
std::string filePath;
std::atomic_bool running;
@ -66,23 +151,35 @@ private:
queue<std::string> errors;
std::mutex current_file_mutex;
std::optional<std::string> current_file;
std::optional<std::string> current_title;
uint16_t signals_occurred = PlaybackSignalNone;
std::mutex signal_mutex;
void set_signal(uint16_t signal);
float prev_pitch, prev_speed, prev_tempo;
public:
Playback();
~Playback();
std::optional<std::string> get_current_file();
double GetPosition();
double GetLength();
void Seek(double position);
void Start(std::string filePath);
bool IsPaused();
void Pause();
void Stop();
PlaybackInstance();
~PlaybackInstance() override;
std::optional<std::string> get_current_file() override;
std::optional<std::string> get_current_title() override;
double GetPosition() override;
double GetLength() override;
void Seek(double position) override;
void Start(std::string filePath) override;
bool IsPaused() override;
void Pause() override;
void Stop() override;
void Update();
bool IsStopped();
bool IsStopped() override;
void SetTempo(float tempo) override;
void SetPitch(float pitch) override;
void SetSpeed(float speed) override;
void SetVolume(float volume) override;
float GetTempo() override;
float GetPitch() override;
float GetSpeed() override;
float GetVolume() override;
float volume;
float speed;
float tempo;
@ -94,8 +191,7 @@ public:
float MinSpeed = 0.25;
float MinPitch = 0.25;
float MinTempo = 0.25;
uint16_t handle_signals(uint16_t signal);
optional<std::string> GetError();
bool ErrorExists();
uint16_t handle_signals(uint16_t signal) override;
optional<std::string> GetError() override;
bool ErrorExists() override;
};

View file

@ -45,3 +45,13 @@ inline std::string to_string_with_decimals(double value, unsigned decimals) {
}
return num_text;
}
inline size_t combine_hashes(std::initializer_list<size_t> hashes) {
std::string values = "^";
values += hashes.size();
values += "@";
for (auto value : values) {
values += value;
values += ";";
}
return std::hash<std::string>()(values);
}