< Back to IRCAM Forum

Library for reading .txt files

Hi everybody,

I’ve made this micro-library (OMRead-txt) to import .txt files into OM. The main idea is to place all .txt files in the library “sources” folder in order to make them accessible to OM. I don’t know if it works in all computers and systems and also, since i’m a beginner in Common Lisp, I don’t know if it is useful to other users or even if is a naive solution.

There is a example of the library in the tutorial and all suggestions are welcome.

Best Regards!

Paulo Henrique Raposo

OMRead-txt.zip (81.3 KB)

Hi Paulo,

Good you have started a library. All new libraries are welcomed for extra functionalities.
In your case, this is already one in OpenMusic’s object you can do by using the textfile object:
Screenshot_2021-01-01_18-13-39
This same object allows you to save or load a textfile also.

Best wishes
K

1 Like

Hi Karim,
Thank you for your response.
My main doubt was about the pathname created through a global variable and if this solution works in all computers and systems (Windows, Mac and Unix). This is the code:

In the library main file

(in-package :om)
(defvar OMRead-txt-path (make-pathname :directory (append (pathname-directory load-pathname) (list “sources”))))

In the file where the functions are located

(in-package :OMRead-txt)

(defun string-to-list (str)
(if (not (streamp str))
(string-to-list (make-string-input-stream str))
(if (listen str)
(cons (read str) (string-to-list str))
nil)))

(defun read-text-file (string)
(let ((stream (open (merge-pathnames om::OMRead-txt-path (parse-namestring (concatenate 'string string “.txt”))))))
(om::flat-once (string-to-list stream))))

I was thinking about load multiple .txt files in the library “sources” folder and how to generate an automatic pathname to do so, without the necessity of the user to insert this pathname for each file. It is also a part of a bigger project for another library, where I intend to load .txt files with previous calculations (huge quantities of data).

Is it make any sense?

Best Regards,

Paulo.

Hi Paulo

Yes it can make sense, however i think it is better not to mix sources of code and text material in the same folder. Maybe think in putting them freely in a folder (it can be also the infile folder of a workspace for instance.)

Best
K

Hi Karin,

I have finished part of the library that I am working on it. It will be called OM-AIS and its for dealing with All Interval Series. Thats why I was looking for a way to load .txt files in the library…

This is the link of the pre-release (for tests only): https://github.com/PHRaposo/OM-AIS

I will be very grateful if you can send me your comments, critics or suggestions.

Best Regards,

Paulo Henrique Raposo

Dear Paulo,

Of course, will take a look and report if necessary for remarks. But it looks very fine for me (just took a fast look on the source code).

Thanx for your contribution.

Best
K

Dear Paulo,

Thank you very much for your contribution, very interesting, congratulations.
If I may, on Linux (Fedora32 - then I will test on Mac El Capitan) I receive a dead function on first of tutorial patches: RQ-AIS. I have searched it on .lisp files and I seem it is absent.

The rest of library should run perfectly, at least at this first rapid test, and it is very fast in calculating results, much more than my library object, I will study your code, thank you again.

Best

fdsdb

Hi Fabio,
thanks for testing the library. I’ve updated the file and it should be working now:

I’ve included, also, a brief explanation about the library. In fact I was not able to create a very fast calculation for all 3956 AIS (on PWGL this calculations lasts less than two seconds) and for this I am using some finished calculations saved in .txt files.
I have doubts about the number of QI Invariants too, because scholars claims that there are only 57 possible solutions and I am getting 60 solutions.
I intend to revise this calculations, add some references about articles and do some more testings before to publish a first version.

Thanks again!

Best,

Paulo

Dear Paulo,

Thank you, also for explanations. Now QR-AIS (not RQ, sorry… - too much algorithmic permutations) runs, but, always on Linux, I have another problem with AIS-calculations tutorial patch:

I have tried to load by hand OMCS library and to restart OM, but the problem persists.

Today I will test it on El Capitan. Sorry I can’t be more useful.

Ciao

Fabio

Hi,

Always me. On El Capitan everything runs perfectly, so I suppose on Linux it could be a problem more by OMCS library than your library. If I succeed in resolving the problem I will post here the result. On Mac the OMCS library is invoked on opening totorial patch, on Fedora 32 it is not.

Best

Fabio

Dear Paulo,

Great it works marvelously well. I will include your library’s link in our db on OpenMusic github project. Just a slight remark. Maybe in your github page you should use the Readme.md up one level in order to show the read me on your project.

Best
K

Dear Fabio,

Are you using the latest OMCS library (vers 1.2) ?
I didn’t have any difficulty loading it on my Debian Linux.
However there seems to be a missing icon, but everything loads well for me,…
Will try on fedora, but i don’t think itis a distribution issue.

Best
K

Dear Paulo,

By the way, you may annouce your new library on a new OM post here if you like, with of course some description.

Best
K

Hi Karin and Fabio,
Thanks again!
I’ve doubled checked the library from a blank workspace and it’s just working fine here (on a MAC OS X High Sierra 10.13.6), but i’ve included a “(require-library :omcs)” code to see if it helps.
Karin, iI will announce the library on a new OM post.

Best,

Paulo

Dear Karim and Paulo,

I was just going to update OMCS on Linux. Now I have done it and I can confirm everything runs without problems, OMCS functions are recognized. Thank you all, ciao

Fabio

Thanks Fabio.

Please, contact me if there is any problem with the library.

Best,

Paulo.