Compare commits
13 Commits
6ee7887bd2
...
f96a642cf0
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | f96a642cf0 | |
Savanni D'Gerinel | c76fccb42e | |
Savanni D'Gerinel | 6b7b830b12 | |
Savanni D'Gerinel | eb95fa7d4a | |
Savanni D'Gerinel | 8de85afa15 | |
Savanni D'Gerinel | 66d692c4c4 | |
Savanni D'Gerinel | 477530c8d1 | |
Savanni D'Gerinel | 4632e59dec | |
Savanni D'Gerinel | e3e55bafed | |
Savanni D'Gerinel | 9b4e0a43ed | |
Savanni D'Gerinel | 3a3cf84c83 | |
Savanni D'Gerinel | 7453e2d8cf | |
Savanni D'Gerinel | d5e8f24cc7 |
|
@ -1,2 +1,4 @@
|
|||
target
|
||||
.direnv/
|
||||
node_modules
|
||||
dist
|
||||
|
|
|
@ -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>.
|
28
flake.lock
28
flake.lock
|
@ -17,16 +17,16 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1672580127,
|
||||
"narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=",
|
||||
"lastModified": 1675237434,
|
||||
"narHash": "sha256-YoFR0vyEa1HXufLNIFgOGhIFMRnY6aZ0IepZF5cYemo=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0874168639713f547c05947c76124f78441ea46c",
|
||||
"rev": "285b3ff0660640575186a4086e1f8dc0df2874b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.05",
|
||||
"ref": "nixos-22.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
|
@ -52,7 +52,7 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"narHash": "sha256-/YOtiDKPUXKKpIhsAds11llfC42ScGW27bbHnNZebco=",
|
||||
"narHash": "sha256-SQNtt71uT++7F3+kHOZ9PEThswk0MnEt6zO2xJdUo/o=",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
|
||||
},
|
||||
|
@ -64,7 +64,23 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"oxalica": "oxalica"
|
||||
"oxalica": "oxalica",
|
||||
"unstable": "unstable"
|
||||
}
|
||||
},
|
||||
"unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1675183161,
|
||||
"narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
21
flake.nix
21
flake.nix
|
@ -2,11 +2,12 @@
|
|||
description = "Lumenescent Dreams Tools";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-22.05";
|
||||
nixpkgs.url = "nixpkgs/nixos-22.11";
|
||||
unstable.url = "nixpkgs/nixos-unstable";
|
||||
oxalica.url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, oxalica }:
|
||||
outputs = { self, nixpkgs, unstable, oxalica }:
|
||||
let
|
||||
version = builtins.string 0 8 self.lastModifiedDate;
|
||||
supportedSystems = [ "x86_64-linux" ];
|
||||
|
@ -16,6 +17,7 @@
|
|||
let
|
||||
rust_overlay = import oxalica;
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
|
||||
pkgs-unstable = import unstable { system = "x86_64-linux"; overlays = [ rust_overlay ]; };
|
||||
rust = pkgs.rust-bin.stable."1.65.0".default.override {
|
||||
extensions = [ "rust-src" ];
|
||||
};
|
||||
|
@ -23,10 +25,23 @@
|
|||
pkgs.mkShell {
|
||||
name = "ld-tools-devshell";
|
||||
buildInputs = [
|
||||
pkgs.pkg-config
|
||||
pkgs.clang
|
||||
pkgs.dbus
|
||||
pkgs.entr
|
||||
pkgs.glib
|
||||
pkgs.gst_all_1.gst-plugins-bad
|
||||
pkgs.gst_all_1.gst-plugins-base
|
||||
pkgs.gst_all_1.gst-plugins-good
|
||||
pkgs.gst_all_1.gst-plugins-ugly
|
||||
pkgs.gst_all_1.gstreamer
|
||||
pkgs.nodejs
|
||||
pkgs.openssl
|
||||
pkgs.pipewire
|
||||
pkgs.pkg-config
|
||||
pkgs.sqlite
|
||||
rust
|
||||
];
|
||||
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "flow"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "flow"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
thiserror = "1"
|
|
@ -0,0 +1,3 @@
|
|||
# Flow
|
||||
|
||||
This is a library to help with application control flow, separating fatal errors from normal recoverable errors. This is almost entirely inspired by [Error Handling in a Correctness-Critical Rust Project](https://sled.rs/errors.html) in the sled.rs library.
|
|
@ -0,0 +1,257 @@
|
|||
//! Control Flow for Correctness-Critical applications
|
||||
//!
|
||||
//! https://sled.rs/errors.html
|
||||
//!
|
||||
//! Where the sled.rs library uses `Result<Result<A, Error>, FatalError>`, these are a little hard to
|
||||
//! work with. This library works out a set of utility functions that allow us to work with the
|
||||
//! nested errors in the same way as a regular Result.
|
||||
use std::error::Error;
|
||||
|
||||
/// Implement this trait for the application's fatal errors.
|
||||
///
|
||||
/// Fatal errors should be things that should trigger an application shutdown. Applications should
|
||||
/// not try to recover from fatal errors, but simply bring the app to the safest shutdown point and
|
||||
/// report the best possible information to the user.
|
||||
///
|
||||
/// Examples: database corruption, or the database is unavailable in an application that cannot
|
||||
/// function without it. Graphics environment cannot be initialized in a GUI app.
|
||||
///
|
||||
/// Applications should generally have only one FatalError type. There are no handling utilities
|
||||
/// for Fatal conditions, so Fatal conditions must be handled through an ordinary `match`
|
||||
/// statement.
|
||||
pub trait FatalError: Error {}
|
||||
|
||||
/// Flow<A, FE, E> represents a return value that might be a success, might be a fatal error, or
|
||||
/// might be a normal handleable error.
|
||||
pub enum Flow<A, FE, E> {
|
||||
/// The operation was successful
|
||||
Ok(A),
|
||||
/// The operation encountered a fatal error. These should be bubbled up to a level that can
|
||||
/// safely shut the application down.
|
||||
Fatal(FE),
|
||||
/// Ordinary errors. These should be handled and the application should recover gracefully.
|
||||
Err(E),
|
||||
}
|
||||
|
||||
impl<A, FE, E> Flow<A, FE, E> {
|
||||
/// Apply an infallible function to a successful value.
|
||||
pub fn map<B, O>(self, mapper: O) -> Flow<B, FE, E>
|
||||
where
|
||||
O: FnOnce(A) -> B,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(mapper(val)),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a potentially fallible function to a successful value.
|
||||
///
|
||||
/// Like `Result.and_then`, the mapping function can itself fail.
|
||||
pub fn and_then<B, O>(self, handler: O) -> Flow<B, FE, E>
|
||||
where
|
||||
O: FnOnce(A) -> Flow<B, FE, E>,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => handler(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Map a normal error from one type to another. This is useful for converting an error from
|
||||
/// one type to another, especially in re-throwing an underlying error. `?` syntax does not
|
||||
/// work with `Flow`, so you will likely need to use this a lot.
|
||||
pub fn map_err<F, O>(self, mapper: O) -> Flow<A, FE, F>
|
||||
where
|
||||
O: FnOnce(E) -> F,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => Flow::Err(mapper(err)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Provide a function to use to recover from (or simply re-throw) an error.
|
||||
pub fn or_else<O, F>(self, handler: O) -> Flow<A, FE, F>
|
||||
where
|
||||
O: FnOnce(E) -> Flow<A, FE, F>,
|
||||
{
|
||||
match self {
|
||||
Flow::Ok(val) => Flow::Ok(val),
|
||||
Flow::Fatal(err) => Flow::Fatal(err),
|
||||
Flow::Err(err) => handler(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert from a normal `Result` type to a `Flow` type. The error condition for a `Result` will
|
||||
/// be treated as `Flow::Err`, never `Flow::Fatal`.
|
||||
impl<A, FE, E> From<Result<A, E>> for Flow<A, FE, E> {
|
||||
fn from(r: Result<A, E>) -> Self {
|
||||
match r {
|
||||
Ok(val) => Flow::Ok(val),
|
||||
Err(err) => Flow::Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience function to create an ok value.
|
||||
pub fn ok<A, FE: FatalError, E: Error>(val: A) -> Flow<A, FE, E> {
|
||||
Flow::Ok(val)
|
||||
}
|
||||
|
||||
/// Convenience function to create an error value.
|
||||
pub fn error<A, FE: FatalError, E: Error>(err: E) -> Flow<A, FE, E> {
|
||||
Flow::Err(err)
|
||||
}
|
||||
|
||||
/// Convenience function to create a fatal value.
|
||||
pub fn fatal<A, FE: FatalError, E: Error>(err: FE) -> Flow<A, FE, E> {
|
||||
Flow::Fatal(err)
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Return early from the current function if the value is a fatal error.
|
||||
macro_rules! return_fatal {
|
||||
($x:expr) => {
|
||||
match $x {
|
||||
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||
Flow::Err(err) => Err(err),
|
||||
Flow::Ok(val) => Ok(val),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Return early from the current function is the value is an error.
|
||||
macro_rules! return_error {
|
||||
($x:expr) => {
|
||||
match $x {
|
||||
Flow::Ok(val) => val,
|
||||
Flow::Err(err) => return Flow::Err(err),
|
||||
Flow::Fatal(err) => return Flow::Fatal(err),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum FatalError {
|
||||
#[error("A fatal error occurred")]
|
||||
FatalError,
|
||||
}
|
||||
impl super::FatalError for FatalError {}
|
||||
impl PartialEq for FatalError {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum Error {
|
||||
#[error("an error occurred")]
|
||||
Error,
|
||||
}
|
||||
impl PartialEq for Error {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Flow<i32, FatalError, Error> {
|
||||
fn eq(&self, rhs: &Self) -> bool {
|
||||
match (self, rhs) {
|
||||
(Flow::Ok(val), Flow::Ok(rhs)) => val == rhs,
|
||||
(Flow::Err(_), Flow::Err(_)) => true,
|
||||
(Flow::Fatal(_), Flow::Fatal(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Flow<i32, FatalError, Error> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Flow::Ok(val) => f.write_fmt(format_args!("Flow::Ok {}", val)),
|
||||
Flow::Err(err) => f.write_fmt(format_args!("Flow::Err {:?}", err)),
|
||||
Flow::Fatal(err) => f.write_fmt(format_args!("Flow::Fatal {:?}", err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_map_things() {
|
||||
let success = ok(15);
|
||||
assert_eq!(ok(16), success.map(|v| v + 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_chain_success() {
|
||||
let success = ok(15);
|
||||
assert_eq!(ok(16), success.and_then(|v| ok(v + 1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_handle_an_error() {
|
||||
let failure = error(Error::Error);
|
||||
assert_eq!(ok(16), failure.or_else(|_| ok(16)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn early_exit_on_fatal() {
|
||||
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_fatal!(ok::<i32, FatalError, Error>(15));
|
||||
match value {
|
||||
Ok(_) => ok(14),
|
||||
Err(err) => error(err),
|
||||
}
|
||||
}
|
||||
|
||||
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_fatal!(error::<i32, FatalError, Error>(Error::Error));
|
||||
match value {
|
||||
Ok(_) => panic!("shouldn't have gotten here"),
|
||||
Err(err) => ok(0),
|
||||
}
|
||||
}
|
||||
|
||||
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||
return_fatal!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fatal_func();
|
||||
assert_eq!(ok_func(), ok(14));
|
||||
assert_eq!(err_func(), ok(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_early_exit_on_all_errors() {
|
||||
fn ok_func() -> Flow<i32, FatalError, Error> {
|
||||
let value = return_error!(ok::<i32, FatalError, Error>(15));
|
||||
assert_eq!(value, 15);
|
||||
ok(14)
|
||||
}
|
||||
|
||||
fn err_func() -> Flow<i32, FatalError, Error> {
|
||||
return_error!(error::<i32, FatalError, Error>(Error::Error));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fn fatal_func() -> Flow<i32, FatalError, Error> {
|
||||
return_error!(fatal::<i32, FatalError, Error>(FatalError::FatalError));
|
||||
panic!("failed to bail");
|
||||
}
|
||||
|
||||
fatal_func();
|
||||
assert_eq!(ok_func(), ok(14));
|
||||
err_func();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="./styles.css" type="text/css" />
|
||||
<title>Music Player</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="currently-playing"> <span class="track-title"> Lindsey Sterling - Elements </span> <span class="player-status">[paused]</span> </div>
|
||||
<div class="controls"><button class="play-pause">Pause</button></div>
|
||||
|
||||
<div class="track-list">
|
||||
<div class="track-list__grouping">
|
||||
<ul class="bulletless-list">
|
||||
<li> By Artist </li>
|
||||
<li> By Album </li>
|
||||
<li> Work Music </li>
|
||||
<li> Dance Music </li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="track-list__tracks">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th> Track # </th>
|
||||
<th> Title </th>
|
||||
<th> Artist </th>
|
||||
<th> Album </th>
|
||||
<th> Length </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 1 </td>
|
||||
<td> Underground </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:24 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 2 </td>
|
||||
<td> Artemis </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 3:54 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 3 </td>
|
||||
<td> Til the Light Goes Out </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:46 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 4 </td>
|
||||
<td> Between Twilight </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 4:20 </td>
|
||||
</tr>
|
||||
<tr class="track-list__track-row">
|
||||
<td> 5 </td>
|
||||
<td> Foreverglow </td>
|
||||
<td> Lindsey Stirling </td>
|
||||
<td> Artemis </td>
|
||||
<td> 3:58 </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="./dist/main.js" type="module"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "music-player-client",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"build": "browserify src/main.ts -p [ tsify ] > dist/bundle.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "exa index.html styles.css src/* | entr -s 'npm run build'"
|
||||
},
|
||||
"author": "Savanni D'Gerinel <savanni@luminescent-dreams.com>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21",
|
||||
"systemjs": "^6.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.191",
|
||||
"babelify": "^10.0.0",
|
||||
"browserify": "^17.0.0",
|
||||
"live-server": "^1.2.2",
|
||||
"tsify": "^5.0.4",
|
||||
"typescript": "^4.9.4",
|
||||
"watchify": "^4.0.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import * as _ from "lodash";
|
||||
|
||||
const replaceTitle = () => {
|
||||
const title = document.querySelector(".js-title");
|
||||
if (title && title.innerHTML) {
|
||||
title.innerHTML = "Music Player Paused";
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
const checkWeatherService = () => {
|
||||
fetch("https://api.weather.gov/")
|
||||
.then((r) => r.json())
|
||||
.then((js) => {
|
||||
const weather = document.querySelector('.js-weather');
|
||||
weather.innerHTML = js.status;
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
const run = () => {
|
||||
replaceTitle();
|
||||
console.log(_.map([4, 8], (x) => x * x));
|
||||
// checkWeatherService();
|
||||
};
|
||||
|
||||
run();
|
|
@ -0,0 +1,39 @@
|
|||
body {
|
||||
background-color: rgb(240, 230, 230);
|
||||
}
|
||||
|
||||
.currently-playing {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.track-list {
|
||||
border: 1px solid black;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.track-list__grouping {
|
||||
padding: 8px;
|
||||
border-style: solid;
|
||||
border-width: 0px 5px 0px 0px;
|
||||
}
|
||||
|
||||
.bulletless-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.track-list__track-row {
|
||||
background-color: rgb(10, 10, 10);
|
||||
}
|
||||
|
||||
.track-list__track-row:nth-child(even) {
|
||||
background-color: rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
.track-list__track-row:nth-child(odd) {
|
||||
background-color: rgb(200, 200, 200);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2015",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"rootDir": "src",
|
||||
"outDir": "./dist",
|
||||
"lib": ["es2016", "DOM"],
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
pub use flow::error;
|
||||
|
||||
pub enum FatalError {
|
||||
UnexpectedError,
|
||||
}
|
||||
|
||||
impl flow::FatalError for FatalError {}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "music-player"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dbus = { version = "0.9.7" }
|
||||
flow = { path = "../../flow" }
|
||||
mpris = { version = "2.0" }
|
||||
rusqlite = { version = "0.28" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = { version = "1.0" }
|
||||
tokio = { version = "1.24", features = ["full"] }
|
||||
url = { version = "2.3" }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
warp = { version = "0.3" }
|
||||
|
||||
[lib]
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of the Luminescent Dreams Tools.
|
||||
|
||||
Luminescent Dreams Tools 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.
|
||||
|
||||
Luminescent Dreams Tools 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use dbus::ffidisp::Connection;
|
||||
use mpris::{FindingError, PlaybackStatus, Player, PlayerFinder, ProgressTick};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::mpsc::{channel, Receiver, Sender, TryRecvError},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
pub enum Message {
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Event {
|
||||
Paused(Track, Duration),
|
||||
Playing(Track, Duration),
|
||||
Stopped,
|
||||
Position(Track, Duration),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DeviceInformation {
|
||||
pub address: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub fn list_devices(conn: Connection) -> Result<Vec<DeviceInformation>, FindingError> {
|
||||
Ok(PlayerFinder::for_connection(conn)
|
||||
.find_all()?
|
||||
.into_iter()
|
||||
.map(|player| DeviceInformation {
|
||||
address: player.unique_name().to_owned(),
|
||||
name: player.identity().to_owned(),
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AudioError {
|
||||
#[error("DBus device was not found")]
|
||||
DeviceNotFound,
|
||||
|
||||
#[error("DBus connection lost or otherwise failed")]
|
||||
ConnectionLost,
|
||||
|
||||
#[error("Specified media cannot be found")]
|
||||
MediaNotFound,
|
||||
|
||||
#[error("Play was ordered, but nothing is in the queue")]
|
||||
NothingInQueue,
|
||||
|
||||
#[error("Unknown dbus error")]
|
||||
DbusError(dbus::Error),
|
||||
|
||||
#[error("Unknown problem with mpris")]
|
||||
MprisError(mpris::DBusError),
|
||||
|
||||
#[error("url parse error {0}")]
|
||||
UrlError(url::ParseError),
|
||||
}
|
||||
|
||||
impl From<dbus::Error> for AudioError {
|
||||
fn from(err: dbus::Error) -> Self {
|
||||
Self::DbusError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mpris::DBusError> for AudioError {
|
||||
fn from(err: mpris::DBusError) -> Self {
|
||||
Self::MprisError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<url::ParseError> for AudioError {
|
||||
fn from(err: url::ParseError) -> Self {
|
||||
Self::UrlError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct TrackId(String);
|
||||
|
||||
impl Default for TrackId {
|
||||
fn default() -> Self {
|
||||
Self(uuid::Uuid::new_v4().as_hyphenated().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for TrackId {
|
||||
fn from(id: String) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<String> for TrackId {
|
||||
fn as_ref<'a>(&'a self) -> &'a String {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TrackInfo {
|
||||
pub track_number: Option<i32>,
|
||||
pub name: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub artist: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Track {
|
||||
pub id: TrackId,
|
||||
pub track_number: Option<i32>,
|
||||
pub name: Option<String>,
|
||||
pub album: Option<String>,
|
||||
pub artist: Option<String>,
|
||||
}
|
||||
|
||||
/*
|
||||
impl From<&mpris::Metadata> for Track {
|
||||
fn from(data: &mpris::Metadata) -> Self {
|
||||
Self {
|
||||
id: data.track_id().unwrap(),
|
||||
track_number: data.track_number(),
|
||||
name: data.title().map(|s| s.to_owned()),
|
||||
album: data.album_name().map(|s| s.to_owned()),
|
||||
artist: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mpris::Metadata> for Track {
|
||||
fn from(data: mpris::Metadata) -> Self {
|
||||
Self::from(&data)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum State {
|
||||
Playing(Track),
|
||||
Paused(Track),
|
||||
Stopped,
|
||||
}
|
||||
|
||||
pub struct CurrentlyPlaying {
|
||||
track: Track,
|
||||
position: Duration,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Capabilities {
|
||||
pub can_control: bool,
|
||||
pub can_pause: bool,
|
||||
pub can_play: bool,
|
||||
pub supports_track_lists: bool,
|
||||
}
|
||||
|
||||
pub trait AudioPlayer {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError>;
|
||||
fn state(&self) -> Result<State, AudioError>;
|
||||
fn play(&self, trackid: url::Url) -> Result<State, AudioError>;
|
||||
fn play_pause(&self) -> Result<State, AudioError>;
|
||||
}
|
||||
|
||||
pub struct GStreamerPlayer {
|
||||
url: url::Url,
|
||||
}
|
||||
|
||||
impl AudioPlayer for GStreamerPlayer {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn state(&self) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn play(&self, trackid: url::Url) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn play_pause(&self) -> Result<State, AudioError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub struct MprisDevice {
|
||||
device_id: String,
|
||||
player: Player,
|
||||
state: State,
|
||||
}
|
||||
|
||||
impl MprisDevice {
|
||||
pub fn new(device_id: String) -> Result<MprisDevice, AudioError> {
|
||||
let connection = Connection::new_session()?;
|
||||
Ok(MprisDevice {
|
||||
device_id: device_id.clone(),
|
||||
player: mpris::Player::new(connection, device_id, 1000)?,
|
||||
state: State::Stopped,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn monitor(&mut self, control_channel: Receiver<Message>) {
|
||||
let (tx, rx) = channel();
|
||||
{
|
||||
let device_id = self.device_id.clone();
|
||||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
MprisDevice::new(device_id)
|
||||
.expect("connect to bus")
|
||||
.monitor_progress(tx);
|
||||
});
|
||||
};
|
||||
|
||||
loop {
|
||||
match control_channel.try_recv() {
|
||||
Ok(Message::Quit) => return,
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => return,
|
||||
}
|
||||
let event = rx.recv().expect("receive should never fail");
|
||||
println!("event received: {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn monitor_progress(&self, tx: Sender<Event>) {
|
||||
let mut tracker = self
|
||||
.player
|
||||
.track_progress(1000)
|
||||
.expect("can get an event stream");
|
||||
loop {
|
||||
let ProgressTick { progress, .. } = tracker.tick();
|
||||
match progress.playback_status() {
|
||||
PlaybackStatus::Playing => {
|
||||
tx.send(Event::Playing(
|
||||
Track::from(progress.metadata()),
|
||||
progress.position(),
|
||||
))
|
||||
.expect("send to succeed");
|
||||
}
|
||||
PlaybackStatus::Paused => {
|
||||
tx.send(Event::Paused(
|
||||
Track::from(progress.metadata()),
|
||||
progress.position(),
|
||||
))
|
||||
.expect("send to succeed");
|
||||
}
|
||||
PlaybackStatus::Stopped => {
|
||||
tx.send(Event::Stopped).expect("send to succeed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioPlayer for MprisDevice {
|
||||
fn capabilities(&self) -> Result<Capabilities, AudioError> {
|
||||
Ok(Capabilities {
|
||||
can_control: self.player.can_control()?,
|
||||
can_pause: self.player.can_pause()?,
|
||||
can_play: self.player.can_play()?,
|
||||
supports_track_lists: self.player.supports_track_lists(),
|
||||
})
|
||||
}
|
||||
|
||||
fn state(&self) -> Result<State, AudioError> {
|
||||
println!(
|
||||
"supports track lists: {:?}",
|
||||
self.player.supports_track_lists()
|
||||
);
|
||||
let metadata = self.player.get_metadata()?;
|
||||
println!("{:?}", metadata);
|
||||
unimplemented!("AudioPlayer state")
|
||||
}
|
||||
|
||||
fn play(&self, track_id: String) -> Result<State, AudioError> {
|
||||
println!("playing: {}", track_id);
|
||||
self.player
|
||||
.go_to(&mpris::TrackID::from(dbus::Path::from(track_id)))?;
|
||||
self.player.play();
|
||||
Ok(State::Stopped)
|
||||
}
|
||||
|
||||
fn play_pause(&self) -> Result<State, AudioError> {
|
||||
self.player.play_pause()?;
|
||||
Ok(State::Stopped)
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,114 @@
|
|||
use flow::Flow;
|
||||
use std::{io::stdin, path::PathBuf, sync::Arc, thread, time::Duration};
|
||||
// use warp::Filter;
|
||||
|
||||
use music_player::{core::Core, database::MemoryIndex};
|
||||
|
||||
/*
|
||||
fn tracks() -> Vec<Track> {
|
||||
vec![
|
||||
Track {
|
||||
track_number: Some(1),
|
||||
name: Some("Underground".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/01 - Underground.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(2),
|
||||
name: Some("Artemis".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/02 - Artemis.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(3),
|
||||
name: Some("Til the Light Goes Out".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from(
|
||||
"/mnt/music/Lindsey Stirling/Artemis/03 - Til the Light Goes Out.ogg",
|
||||
),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(4),
|
||||
name: Some("Between Twilight".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/04 - Between Twilight.ogg"),
|
||||
},
|
||||
Track {
|
||||
track_number: Some(5),
|
||||
name: Some("Foreverglow".to_owned()),
|
||||
album: Some("Artemis".to_owned()),
|
||||
artist: Some("Lindsey Stirling".to_owned()),
|
||||
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/05 - Foreverglow.ogg"),
|
||||
},
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
match Core::new(Arc::new(MemoryIndex::new())) {
|
||||
Flow::Ok(core) => {
|
||||
let mut buf = String::new();
|
||||
let _ = stdin().read_line(&mut buf).unwrap();
|
||||
core.exit();
|
||||
}
|
||||
Flow::Err(err) => println!("non-fatal error: {:?}", err),
|
||||
Flow::Fatal(err) => println!("fatal error: {:?}", err),
|
||||
}
|
||||
|
||||
/*
|
||||
let connection = Connection::new_session().expect("to connect to dbus");
|
||||
|
||||
for player in list_players(connection) {
|
||||
println!("player found: {}", player.identity());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
let devices = warp::path!("api" / "v1" / "devices")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let conn = Connection::new_session().expect("to connect to dbus");
|
||||
warp::reply::json(&list_devices(conn))
|
||||
});
|
||||
|
||||
let track_list = warp::path!("api" / "v1" / "tracks")
|
||||
.and(warp::get())
|
||||
.map(|| warp::reply::json(&tracks()));
|
||||
let tracks_for_artist = warp::path!("api" / "v1" / "artist" / String)
|
||||
.and(warp::get())
|
||||
.map(|_artist: String| warp::reply::json(&tracks()));
|
||||
let tracks_for_album = warp::path!("api" / "v1" / "album" / String)
|
||||
.and(warp::get())
|
||||
.map(|_album: String| warp::reply::json(&tracks()));
|
||||
|
||||
let queue = warp::path!("api" / "v1" / "queue")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let conn = Connection::new_session().expect("to connect to dbus");
|
||||
warp::reply::json(&list_tracks(conn))
|
||||
});
|
||||
|
||||
let playing_status = warp::path!("api" / "v1" / "play-pause")
|
||||
.and(warp::get())
|
||||
.map(|| warp::reply::json(&PlayPause::Paused));
|
||||
|
||||
let routes = devices
|
||||
.or(track_list)
|
||||
.or(tracks_for_album)
|
||||
.or(tracks_for_artist)
|
||||
.or(queue)
|
||||
.or(playing_status);
|
||||
let server = warp::serve(routes);
|
||||
server
|
||||
.run(SocketAddr::new(
|
||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
8002,
|
||||
))
|
||||
.await;
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
use crate::{
|
||||
database::{Database, MemoryIndex, MusicIndex},
|
||||
Error, FatalError,
|
||||
};
|
||||
use flow::{error, fatal, ok, return_error, return_fatal, Flow};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
||||
Arc,
|
||||
},
|
||||
thread,
|
||||
thread::JoinHandle,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ScannerError {
|
||||
#[error("Cannot scan {0}")]
|
||||
CannotScan(PathBuf),
|
||||
#[error("IO error {0}")]
|
||||
IO(std::io::Error),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ScannerError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self::IO(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ControlMsg {
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub enum TrackMsg {
|
||||
DbUpdate,
|
||||
}
|
||||
|
||||
pub enum PlaybackMsg {
|
||||
PositionUpdate,
|
||||
Playing,
|
||||
Pausing,
|
||||
Stopping,
|
||||
}
|
||||
|
||||
pub struct Core {
|
||||
db: Arc<dyn MusicIndex>,
|
||||
track_handle: JoinHandle<()>,
|
||||
track_rx: Receiver<TrackMsg>,
|
||||
playback_handle: JoinHandle<()>,
|
||||
playback_rx: Receiver<PlaybackMsg>,
|
||||
control_tx: Sender<ControlMsg>,
|
||||
}
|
||||
|
||||
fn scan_frequency() -> Duration {
|
||||
Duration::from_secs(60)
|
||||
}
|
||||
|
||||
pub struct FileScanner {
|
||||
db: Arc<dyn MusicIndex>,
|
||||
control_rx: Receiver<ControlMsg>,
|
||||
tracker_tx: Sender<TrackMsg>,
|
||||
next_scan: Instant,
|
||||
music_directories: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl FileScanner {
|
||||
fn new(
|
||||
db: Arc<dyn MusicIndex>,
|
||||
roots: Vec<PathBuf>,
|
||||
control_rx: Receiver<ControlMsg>,
|
||||
tracker_tx: Sender<TrackMsg>,
|
||||
) -> Self {
|
||||
Self {
|
||||
db,
|
||||
control_rx,
|
||||
tracker_tx,
|
||||
next_scan: Instant::now(),
|
||||
music_directories: roots,
|
||||
}
|
||||
}
|
||||
|
||||
fn scan(&mut self) {
|
||||
loop {
|
||||
match self.control_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(ControlMsg::Exit) => return,
|
||||
Err(RecvTimeoutError::Timeout) => (),
|
||||
Err(RecvTimeoutError::Disconnected) => return,
|
||||
}
|
||||
if Instant::now() >= self.next_scan {
|
||||
for root in self.music_directories.iter() {
|
||||
self.scan_dir(vec![root.clone()]);
|
||||
}
|
||||
self.next_scan = Instant::now() + scan_frequency();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_dir(&self, mut paths: Vec<PathBuf>) -> Flow<(), FatalError, ScannerError> {
|
||||
while let Some(dir) = paths.pop() {
|
||||
println!("scanning {:?}", dir);
|
||||
return_error!(self.scan_dir_(&mut paths, dir));
|
||||
}
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn scan_dir_(
|
||||
&self,
|
||||
paths: &mut Vec<PathBuf>,
|
||||
dir: PathBuf,
|
||||
) -> Flow<(), FatalError, ScannerError> {
|
||||
let dir_iter = return_error!(Flow::from(dir.read_dir().map_err(ScannerError::from)));
|
||||
for entry in dir_iter {
|
||||
match entry {
|
||||
Ok(entry) if entry.path().is_dir() => paths.push(entry.path()),
|
||||
Ok(entry) => {
|
||||
let _ = return_fatal!(self.scan_file(entry.path()).or_else(|err| {
|
||||
println!("scan_file failed: {:?}", err);
|
||||
ok::<(), FatalError, ScannerError>(())
|
||||
}));
|
||||
()
|
||||
}
|
||||
Err(err) => {
|
||||
println!("scan_dir could not read path: ({:?})", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn scan_file(&self, path: PathBuf) -> Flow<(), FatalError, ScannerError> {
|
||||
ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Core {
|
||||
pub fn new(db: Arc<dyn MusicIndex>) -> Flow<Core, FatalError, Error> {
|
||||
let (control_tx, control_rx) = channel::<ControlMsg>();
|
||||
|
||||
let (track_handle, track_rx) = {
|
||||
let (track_tx, track_rx) = channel();
|
||||
let db = db.clone();
|
||||
let track_handle = thread::spawn(move || {
|
||||
FileScanner::new(
|
||||
db,
|
||||
vec![PathBuf::from("/home/savanni/Music/")],
|
||||
control_rx,
|
||||
track_tx,
|
||||
)
|
||||
.scan();
|
||||
});
|
||||
(track_handle, track_rx)
|
||||
};
|
||||
|
||||
let (playback_handle, playback_rx) = {
|
||||
let (playback_tx, playback_rx) = channel();
|
||||
let playback_handle = thread::spawn(move || {});
|
||||
(playback_handle, playback_rx)
|
||||
};
|
||||
|
||||
ok(Core {
|
||||
db,
|
||||
track_handle,
|
||||
track_rx,
|
||||
playback_handle,
|
||||
playback_rx,
|
||||
control_tx,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn exit(&self) {
|
||||
let _ = self.control_tx.send(ControlMsg::Exit);
|
||||
/*
|
||||
self.track_handle.join();
|
||||
self.playback_handle.join();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
|
@ -0,0 +1,106 @@
|
|||
use crate::{
|
||||
audio::{Track, TrackId, TrackInfo},
|
||||
FatalError,
|
||||
};
|
||||
use flow::{error, ok, Flow};
|
||||
use rusqlite::Connection;
|
||||
use std::collections::HashMap;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DatabaseError {
|
||||
#[error("database is unreadable")]
|
||||
DatabaseUnreadable,
|
||||
#[error("unhandled database problem: {0}")]
|
||||
UnhandledError(rusqlite::Error),
|
||||
}
|
||||
|
||||
pub trait MusicIndex: Sync + Send {
|
||||
fn add_track(&mut self, track: &TrackInfo) -> Flow<Track, FatalError, DatabaseError>;
|
||||
fn remove_track(&mut self, id: &TrackId) -> Flow<(), FatalError, DatabaseError>;
|
||||
fn get_track_info(&self, id: &TrackId) -> Flow<Option<Track>, FatalError, DatabaseError>;
|
||||
}
|
||||
|
||||
pub struct MemoryIndex {
|
||||
tracks: RwLock<HashMap<TrackId, Track>>,
|
||||
}
|
||||
|
||||
impl MemoryIndex {
|
||||
pub fn new() -> MemoryIndex {
|
||||
MemoryIndex {
|
||||
tracks: RwLock::new(HashMap::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MusicIndex for MemoryIndex {
|
||||
fn add_track(&mut self, info: &TrackInfo) -> Flow<Track, FatalError, DatabaseError> {
|
||||
let id = TrackId::default();
|
||||
let track = Track {
|
||||
id: id.clone(),
|
||||
track_number: info.track_number,
|
||||
name: info.name.clone(),
|
||||
album: info.album.clone(),
|
||||
artist: info.artist.clone(),
|
||||
};
|
||||
let mut tracks = self.tracks.write().unwrap();
|
||||
tracks.insert(id, track.clone());
|
||||
ok(track)
|
||||
}
|
||||
|
||||
fn remove_track(&mut self, id: &TrackId) -> Flow<(), FatalError, DatabaseError> {
|
||||
let mut tracks = self.tracks.write().unwrap();
|
||||
tracks.remove(&id);
|
||||
ok(())
|
||||
}
|
||||
|
||||
fn get_track_info<'a>(
|
||||
&'a self,
|
||||
id: &TrackId,
|
||||
) -> Flow<Option<Track>, FatalError, DatabaseError> {
|
||||
let track = {
|
||||
let tracks = self.tracks.read().unwrap();
|
||||
tracks.get(&id).cloned()
|
||||
};
|
||||
ok(track)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ManagedConnection<'a> {
|
||||
pool: &'a Database,
|
||||
conn: Option<Connection>,
|
||||
}
|
||||
|
||||
impl<'a> Drop for ManagedConnection<'a> {
|
||||
fn drop(&mut self) {
|
||||
self.pool.r(self.conn.take().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
path: PathBuf,
|
||||
pool: Arc<Mutex<Vec<Connection>>>,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new(path: PathBuf) -> Flow<Database, FatalError, DatabaseError> {
|
||||
let connection = match Connection::open(path.clone()) {
|
||||
Ok(connection) => connection,
|
||||
Err(err) => return error(DatabaseError::UnhandledError(err)),
|
||||
};
|
||||
ok(Database {
|
||||
path,
|
||||
pool: Arc::new(Mutex::new(vec![connection])),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn r(&self, conn: Connection) {
|
||||
let mut pool = self.pool.lock().unwrap();
|
||||
pool.push(conn);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
pub mod audio;
|
||||
pub mod core;
|
||||
pub mod database;
|
||||
use database::DatabaseError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("Database error: {0}")]
|
||||
DatabaseError(DatabaseError),
|
||||
}
|
||||
|
||||
impl From<DatabaseError> for Error {
|
||||
fn from(err: DatabaseError) -> Self {
|
||||
Self::DatabaseError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FatalError {
|
||||
#[error("Unexpected error")]
|
||||
UnexpectedError,
|
||||
}
|
||||
|
||||
impl flow::FatalError for FatalError {}
|
|
@ -0,0 +1,514 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-expr"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0357a6402b295ca3a86bc148e84df46c02e41f41fef186bda662557ef6328aa"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gio-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9b693b8e39d042a95547fc258a7b07349b1f0b48f4b2fa3108ba3c51c0b5229"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib"
|
||||
version = "0.16.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd4df61a866ed7259d6189b8bcb1464989a77f1d85d25d002279bbe9dd38b2f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
"gio-sys",
|
||||
"glib-macros",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-macros"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e084807350b01348b6d9dbabb724d1a0bb987f47a2c85de200e98e12e30733bf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"proc-macro-crate",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glib-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61a4f46316d06bfa33a7ac22df6f0524c8be58e3db2d9ca99ccb1f357b62a65"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gobject-sys"
|
||||
version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3520bb9c07ae2a12c7f2fbb24d4efc11231c8146a86956413fb1a79bb760a0f1"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer"
|
||||
version = "0.19.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61af131b56332ec386a8ea538d961d0c6937054fb2771a9a505395f8471b7b0e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"glib",
|
||||
"gstreamer-sys",
|
||||
"libc",
|
||||
"muldiv",
|
||||
"num-integer",
|
||||
"num-rational",
|
||||
"once_cell",
|
||||
"option-operations",
|
||||
"paste",
|
||||
"pretty-hex",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gstreamer-sys"
|
||||
version = "0.19.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "545f52ad8a480732cc4290fd65dfe42952c8ae374fe581831ba15981fedf18a4"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "muldiv"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
|
||||
|
||||
[[package]]
|
||||
name = "nom8"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "option-operations"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c26d27bb1aeab65138e4bf7666045169d1717febcc9ff870166be8348b223d0"
|
||||
dependencies = [
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "pretty-hex"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||
|
||||
[[package]]
|
||||
name = "streamer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gstreamer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2955b1fe31e1fa2fbd1976b71cc69a606d7d4da16f6de3333d0c92d51419aeff"
|
||||
dependencies = [
|
||||
"cfg-expr",
|
||||
"heck",
|
||||
"pkg-config",
|
||||
"toml",
|
||||
"version-compare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"nom8",
|
||||
"toml_datetime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "streamer"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gstreamer = "0.19.7"
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
use gstreamer::{format::ClockTime, prelude::*, MessageView};
|
||||
use std::{thread, time, time::Duration};
|
||||
|
||||
fn main() {
|
||||
gstreamer::init().unwrap();
|
||||
|
||||
let uri = "file:///home/savanni/Music/Lindsey%20Stirling/Artemis/01%20-%20Underground.mp3.mp3";
|
||||
let pipeline = gstreamer::parse_launch(&format!("playbin uri={}", uri)).unwrap();
|
||||
pipeline.set_state(gstreamer::State::Playing).unwrap();
|
||||
|
||||
let message_handler = {
|
||||
let pipeline = pipeline.clone();
|
||||
thread::spawn(move || {
|
||||
let bus = pipeline.bus().unwrap();
|
||||
for msg in bus.iter_timed(gstreamer::ClockTime::NONE) {
|
||||
match msg.view() {
|
||||
MessageView::Eos(_) => (),
|
||||
MessageView::Error(err) => {
|
||||
println!(
|
||||
"Error from {:?}: {} ({:?})",
|
||||
err.src().map(|s| s.path_string()),
|
||||
err.error(),
|
||||
err.debug()
|
||||
);
|
||||
}
|
||||
msg => println!("{:?}", msg),
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let query_handler = {
|
||||
let pipeline = pipeline.clone();
|
||||
thread::spawn(move || loop {
|
||||
let position: Option<ClockTime> = pipeline.query_position();
|
||||
let duration: Option<ClockTime> = pipeline.query_duration();
|
||||
println!("{:?} {:?}", position, duration);
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
})
|
||||
};
|
||||
|
||||
message_handler.join();
|
||||
query_handler.join();
|
||||
|
||||
pipeline.set_state(gstreamer::State::Null).unwrap();
|
||||
}
|
Loading…
Reference in New Issue